Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>Throughout this answer I'm going to talk about Haskell 98 and SML.</em></p> <p>Both type systems have the same foundations really, <a href="http://en.wikipedia.org/wiki/System_F">System F</a>. This means you have basic parametric polymorphism</p> <pre><code>foo :: a -&gt; b -&gt; a foo : 'a -&gt; 'b -&gt; 'c </code></pre> <p>SML provides functors and modules and Haskell type classes, but both of these are really built on top of a core calculus.</p> <p>The most interesting difference is that Haskell is System Fw, which is a souped up version of System F. In particular, it provides a richer notion of kinds (the types of types) allowing for things like</p> <pre><code>data Foo f a = Foo (f a) </code></pre> <p>Notice here that <code>f</code> is a function from a type onto another type, it's kind in other words is <code>* -&gt; *</code>. In fact, Haskell 98 + Type families + PolyKinds + DataKinds extends this further by allowing arbitrary type functions. This gives you something like simply typed lambda calculus with types. For example, here's a church encoding of type level lists</p> <pre class="lang-hs prettyprint-override"><code>{-# LANGUAGE TypeFamilies, EmptyDataDecls #-} -- So we can box things up to partially apply them type family Eval e type instance Eval (Car a b) = a type instance Eval (Cdr a b) = b type instance Eval (Cons a b f) = Eval (f a b) data Car a b data Cdr a b data Cons a b (f :: * -&gt; * -&gt; *) type First p = Eval (p Car) type Second p = Eval (p Cdr) foo :: First (Cons (First (Cons Int Bool)) String) foo = 1 </code></pre> <p>This isn't expressible in SML's core type system, however with functors, one can hack around this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload