Last active
August 10, 2018 16:56
-
-
Save greatBigDot/32f6667060901bdc8b7d81a03bee5cea to your computer and use it in GitHub Desktop.
An attempt to understand Haskell's various ways to get a partially-collapsed type hierarchy and partially-dependent types, via algebraic structures implemented as typeclasses.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE EmptyDataDecls, TypeOperators, LiberalTypeSynonyms, ExistentialQuantification, ExplicitForAll #-} | |
| {-# LANGUAGE GADTSyntax, GADTs, DuplicateRecordFields, NamedFieldPuns, MultiParamTypeClasses, FlexibleContexts, TypeSynonymInstances, FlexibleInstances #-} | |
| {-# LANGUAGE FunctionalDependencies, TypeFamilies, TypeFamilyDependencies, ConstraintKinds, ScopedTypeVariables #-} | |
| {-# LANGUAGE DataKinds, PolyKinds, KindSignatures, TypeInType, TypeApplications, ImplicitParams, NamedWildCards, RankNTypes #-} | |
| {-# LANGUAGE ExplicitNamespaces, MonoLocalBinds, DisambiguateRecordFields, ConstrainedClassMethods #-} | |
| --- ^ I just grabbed anything that looked remotely useful. | |
| module Algebraics.Data.Field where | |
| import GHC.TypeLits | |
| import GHC.TypeNats | |
| import Data.Kind hiding ((*)) | |
| import Data.Type.Equality | |
| class (Eq k) => MagmaId k where | |
| type family Zero :: k | |
| -- data Add :: k -> k -> k | |
| -- addIdl :: forall (x :: k) . (Add x Zero :~: x) | |
| -- addIdR :: forall (x :: k) . (Add Zero x :~: x) | |
| -- Doesn't work; `GHC.Types.Nat` isn't part of `Eq`, since it isn't actually the Peano numbers. No inductive pattern matching is possible, apparently. | |
| instance MagmaId Nat where | |
| type instance Zero = 0 | |
| -- data Add = '(+) | |
| -- addIdl = Refl | |
| -- addIdR = Refl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment