-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Milestone
Description
Define TypeClassLang, a new source language with type classes.
TypeClassLang should have both typed and untyped variants - i.e. it can be in either "mode". This could be implemented by embedding option types in its syntax, or mirroring PureLang's :'a cexp type, or otherwise.
Programs
TypeClassLang programs consist of:
- data type and exception declarations
- type class and instance declarations
- top-level definitions, each with accompanying type signature
Expressions should mirror those of PureLang, except:
- TypeClassLang should contain only rich case syntax, not basic
Case- This should effectively mirror
NestedCasein PureLang
- This should effectively mirror
- Ideally we should incorporate pattern guards too
- At first, we can translate only the subset of syntax that PureLang supports - later we can decide how to compile guards and so on, but the syntax should be designed with everything in mind from the start
- The syntax should contain a constructor for user type annotations (similar to that of CakeML)
Type class and instance declarations
- Type classes are applied to a single type variables only. Multi-parameter type classes are more complicated, and usually go hand-in-hand with "functional dependencies" (https://en.wikibooks.org/wiki/Haskell/Advanced_type_classes)
- Series of definitions ("methods") with type signatures and (optional) default operations.
- Need an idea of minimal definitions: GHC-style pragma, but stick to DNF for simplicity.
- May contain context (i.e. one or more superclasses) e.g.
class (Eq a) => Ord a where compare :: a -> a -> Ordering (<), (<=), (>=), (>) :: a -> a -> Bool max, min :: a -> a -> a - Method types are regular types, and so can have their own context
- Instances are similar: a series of method declarations.
- May also be constrained by context, e.g.
instance Eq a => Eq [a] where
- May also be constrained by context, e.g.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels