Skip to content

Instantly share code, notes, and snippets.

View afldcr's full-sized avatar

Alex Feldman-Crough afldcr

View GitHub Profile
@stelleg
stelleg / hm_scott.lhs
Last active July 4, 2016 10:42
Hindley Milner + Scott Encoding Musings
Sometimes it would be nice if a type system could automatically "do it's best"
to restrict what a value will be. For example, the type `Bool` is the compiler
saying the value will either be `True` or `False`, but it doesn't know which.
What we want is the compiler to be able to be precise when possible, so instead
of always saying `Bool` (or "I don't know"), it could say `True`, `False`, or
`Bool`. This gist shows how Hindley Milner already has this capability that can
be exercised by using Church or Scott encodings of simple data types.
> {-# LANGUAGE RankNTypes #-}
> import qualified Data.Maybe as M