]> Git — Sourcephile - haskell/symantic.git/commit
Revamp the type system.
authorJulien Moutinho <julm+symantic@autogeree.net>
Thu, 24 Nov 2016 04:47:58 +0000 (05:47 +0100)
committerJulien Moutinho <julm+symantic@autogeree.net>
Thu, 24 Nov 2016 06:01:14 +0000 (07:01 +0100)
commit87b7beca0f0fe347fa32c2cdc61bcaa1e334a421
treeee7672368e7ae10d1bd320d3f708b2bb55530107
parent63a7ffe02d6c84614cc4891bdded728f85b5d36f
Revamp the type system.

This is definitively much more correct, simple and powerful this way:
kinds are now properly handled,
type constraints capture is now quite neat,
and usable type variables should be possible.

Though the current code may seem obvious and natural
for the task at hand, it required
first to know that this was indeed this task that has to be done…

Indeed I was previously much more focused on the symantics part,
but this happened when I decided to put a day or two
to check if type inferencing would indeed be possible with the previous type system,
I rapidly convinced myself that I couldn't handle type variables as required,
so I then put aside the previous type system to work anew
from the main (mono)type of Top,
which also appears in Write You a Haskell:

data Type
 =   TVar TVar
 |   TCon String
 |   TArr Type Type

As in the previous type system,
I first tried to have Type indexing an Haskell type (h)
by using the usual GADTs way,
which was surprisingly possible for every kind:
once I realized this could be done through Proxy
(this definitively is a very important type
to compute with GHC's type system),
and found that the type application could be handled
with a type family, which could effectively let me build types
from an AST, the type family's result just stays abstract,
and GADTs put constraints in scope with it in them.

The Index GADT of GLambda was my inspiration to handle type constants
through a type list of them, and thus drop the previous approach
which was indexing types (and not type constants)
and required much more code.

I then tried to have Type always well-formed through GADTs,
my first attempt was (stupidly) to only check the arity,
then I realized it was not enough and introduced a Kind type.

At this point I was able to kindcheck an AST of a type,
but failed to replicate the previous approach to capture a Constraint,
hopefully I then tried (without much hope it would work)
to do the "obvious thing" (since this is what GHC does),
that is to add a type constraint kind into Kind,
which proved itself quite rewarding.
Surprisingly I've quickly found that introducing UnProxy
enables to capture Constraints which need to work on abstract types,
like (Eq a) to prove (Eq (Maybe a)).

Work ahead is to try to update the previous approach
to build expressions with symantics.
Then later to try again type inferencing.

Cheers :-)
120 files changed:
Language/Symantic.hs
Language/Symantic/AST/Test.hs [deleted file]
Language/Symantic/Expr.hs [deleted file]
Language/Symantic/Expr/Alt.hs [deleted file]
Language/Symantic/Expr/Applicative.hs [deleted file]
Language/Symantic/Expr/Applicative/HLint.hs [deleted symlink]
Language/Symantic/Expr/Applicative/Test.hs [deleted file]
Language/Symantic/Expr/Bool.hs [deleted file]
Language/Symantic/Expr/Bool/HLint.hs [deleted symlink]
Language/Symantic/Expr/Bool/Test.hs [deleted file]
Language/Symantic/Expr/Char.hs [deleted file]
Language/Symantic/Expr/Either.hs [deleted file]
Language/Symantic/Expr/Eq.hs [deleted file]
Language/Symantic/Expr/Eq/HLint.hs [deleted symlink]
Language/Symantic/Expr/Eq/Test.hs [deleted file]
Language/Symantic/Expr/Error.hs [deleted file]
Language/Symantic/Expr/Foldable.hs [deleted file]
Language/Symantic/Expr/Foldable/HLint.hs [deleted symlink]
Language/Symantic/Expr/Foldable/Test.hs [deleted file]
Language/Symantic/Expr/From.hs [deleted file]
Language/Symantic/Expr/Functor.hs [deleted file]
Language/Symantic/Expr/Functor/HLint.hs [deleted symlink]
Language/Symantic/Expr/Functor/Test.hs [deleted file]
Language/Symantic/Expr/HLint.hs [deleted symlink]
Language/Symantic/Expr/IO.hs [deleted file]
Language/Symantic/Expr/If.hs [deleted file]
Language/Symantic/Expr/If/HLint.hs [deleted symlink]
Language/Symantic/Expr/If/Test.hs [deleted file]
Language/Symantic/Expr/Int.hs [deleted file]
Language/Symantic/Expr/Int/HLint.hs [deleted symlink]
Language/Symantic/Expr/Int/Test.hs [deleted file]
Language/Symantic/Expr/Integer.hs [deleted file]
Language/Symantic/Expr/Integral.hs [deleted file]
Language/Symantic/Expr/Lambda.hs [deleted file]
Language/Symantic/Expr/Lambda/HLint.hs [deleted symlink]
Language/Symantic/Expr/Lambda/Test.hs [deleted file]
Language/Symantic/Expr/List.hs [deleted file]
Language/Symantic/Expr/List/HLint.hs [deleted symlink]
Language/Symantic/Expr/List/Test.hs [deleted file]
Language/Symantic/Expr/Map.hs [deleted file]
Language/Symantic/Expr/Map/HLint.hs [deleted symlink]
Language/Symantic/Expr/Map/Test.hs [deleted file]
Language/Symantic/Expr/Maybe.hs [deleted file]
Language/Symantic/Expr/Maybe/HLint.hs [deleted symlink]
Language/Symantic/Expr/Maybe/Test.hs [deleted file]
Language/Symantic/Expr/Monad.hs [deleted file]
Language/Symantic/Expr/Monad/HLint.hs [deleted symlink]
Language/Symantic/Expr/Monad/Test.hs [deleted file]
Language/Symantic/Expr/MonoFunctor.hs [deleted file]
Language/Symantic/Expr/MonoFunctor/HLint.hs [deleted symlink]
Language/Symantic/Expr/MonoFunctor/Test.hs [deleted file]
Language/Symantic/Expr/Monoid.hs [deleted file]
Language/Symantic/Expr/Num.hs [deleted file]
Language/Symantic/Expr/Ord.hs [deleted file]
Language/Symantic/Expr/Root.hs [deleted file]
Language/Symantic/Expr/Test.hs [deleted file]
Language/Symantic/Expr/Text.hs [deleted file]
Language/Symantic/Expr/Traversable.hs [deleted file]
Language/Symantic/Expr/Traversable/HLint.hs [deleted symlink]
Language/Symantic/Expr/Traversable/Test.hs [deleted file]
Language/Symantic/Expr/Tuple.hs [deleted file]
Language/Symantic/Lib/Control/HLint.hs [deleted symlink]
Language/Symantic/Lib/Control/Monad.hs [deleted file]
Language/Symantic/Lib/Data/Bool.hs [deleted file]
Language/Symantic/Lib/Data/Peano.hs
Language/Symantic/Repr.hs [deleted file]
Language/Symantic/Repr/Dup.hs [deleted file]
Language/Symantic/Repr/HLint.hs [deleted symlink]
Language/Symantic/Repr/Host.hs [deleted file]
Language/Symantic/Repr/Host/HLint.hs [deleted symlink]
Language/Symantic/Repr/Host/Test.hs [deleted file]
Language/Symantic/Repr/Test.hs [deleted file]
Language/Symantic/Repr/Text.hs [deleted file]
Language/Symantic/Repr/Text/HLint.hs [deleted symlink]
Language/Symantic/Repr/Text/Test.hs [deleted file]
Language/Symantic/Test.hs
Language/Symantic/Trans.hs [deleted file]
Language/Symantic/Trans/Bool.hs [deleted file]
Language/Symantic/Trans/Bool/Const.hs [deleted file]
Language/Symantic/Trans/Bool/Const/Test.hs [deleted file]
Language/Symantic/Trans/Bool/HLint.hs [deleted symlink]
Language/Symantic/Trans/Bool/Test.hs [deleted file]
Language/Symantic/Trans/Common.hs [deleted file]
Language/Symantic/Trans/HLint.hs [deleted symlink]
Language/Symantic/Trans/Test.hs [deleted file]
Language/Symantic/Type.hs [deleted file]
Language/Symantic/Type/Alt.hs [deleted file]
Language/Symantic/Type/Bool.hs [deleted file]
Language/Symantic/Type/Char.hs [deleted file]
Language/Symantic/Type/Constraint.hs [deleted file]
Language/Symantic/Type/Either.hs [deleted file]
Language/Symantic/Type/Error.hs [deleted file]
Language/Symantic/Type/Family.hs [deleted file]
Language/Symantic/Type/Fun.hs [deleted file]
Language/Symantic/Type/HLint.hs [deleted symlink]
Language/Symantic/Type/IO.hs [deleted file]
Language/Symantic/Type/Int.hs [deleted file]
Language/Symantic/Type/Integer.hs [deleted file]
Language/Symantic/Type/List.hs [deleted file]
Language/Symantic/Type/Map.hs [deleted file]
Language/Symantic/Type/Maybe.hs [deleted file]
Language/Symantic/Type/Ordering.hs [deleted file]
Language/Symantic/Type/Root.hs [deleted file]
Language/Symantic/Type/Test.hs [deleted file]
Language/Symantic/Type/Text.hs [deleted file]
Language/Symantic/Type/Tuple.hs [deleted file]
Language/Symantic/Type/Type0.hs [deleted file]
Language/Symantic/Type/Type1.hs [deleted file]
Language/Symantic/Type/Type2.hs [deleted file]
Language/Symantic/Type/Unit.hs [deleted file]
Language/Symantic/Type/Var.hs [deleted file]
Language/Symantic/Typing.hs [new file with mode: 0644]
Language/Symantic/Typing/Constant.hs [new file with mode: 0644]
Language/Symantic/Typing/Constraint.hs [new file with mode: 0644]
Language/Symantic/Typing/HLint.hs [moved from Language/Symantic/AST/HLint.hs with 100% similarity]
Language/Symantic/Typing/Kind.hs [new file with mode: 0644]
Language/Symantic/Typing/Syntax.hs [new file with mode: 0644]
Language/Symantic/Typing/Test.hs [new file with mode: 0644]
Language/Symantic/Typing/Type.hs [new file with mode: 0644]
symantic.cabal