to JavaScript” • Learn more at purescript.org or on #purescript • Goals: ◦ Build the language I want to use every day ◦ Explore how types can improve web programming ◦ Try out some new type system ideas ◦ Provide a fun project for Haskell OSS newcomers
where state :: (s -> Tuple s a) -> m a data Z data S n -- Peano naturals class Add n m r | n m -> r instance addZ :: Add Z n n instance addS :: Add n m r => Add (S n) m (S r)
to generate a fresh type variable which does not unify with other types. These are called skolem constants. At the end of type checking, we need to check that no skolem constants escaped their scope. (Example)
class constraints, we insert a placeholder for a dictionary into the expression. This is called elaboration or dictionary-passing. These placeholders will get replaced during the solving phase. (Example)
during solving. These unifications can cause more instances to become applicable, solving new constraints. So the solver loops until no new type information can be learned. (Example)
types (actually, association lists) • Rows can have duplicate labels • Unification of rows must ignore order of different labels but preserve order of duplicates • “row of k”, spelled # k is a new kind for each kind k (Example)
Int) flatten = ?IForgot Hole 'IForgot' has the inferred type List (Maybe Int) -> Maybe (List Int) You could substitute the hole with one of these values: Data.Monoid.mempty :: forall m. Monoid m => m Data.Traversable.sequence :: forall a m t. Traversable t => Applicative m => t (m a) -> m (t a)
-> r instance typeEq :: TypeEq a a True instance typeNotEq :: TypeEq a b False -- ← overlapping! instances instance typeEq :: TypeEq a a True instance typeNotEq :: TypeEq a b False
polymorphism less ad hoc Philip Wadler • Type Classes with Functional Dependencies Mark P. Jones • Instance Chains: Type Class Programming Without Overlapping Instances J. Garrett Morris and Mark P. Jones