This blog post series has moved here.
You might also be interested in the 2016 version.
| ## Principal type-schemes for functional programs | |
| **Luis Damas and Robin Milner, POPL '82** | |
| > module W where | |
| > import Data.List | |
| > import Data.Maybe | |
| > import Data.Function |
| module Tree where | |
| data Binder = Wildcard | Zero | Succ Binder deriving (Show) | |
| data Tree = Covered | Uncovered | Branch Tree Tree | |
| color :: Tree -> Binder -> Tree | |
| color _ Wildcard = Covered | |
| color Covered _ = Covered | |
| color Uncovered Zero = Branch Covered Uncovered |
| module Main where | |
| -- We will define our checker by piecing together functions based on the various types of binders. | |
| -- We use prisms to abstract over the data constructors representing binders | |
| type Prism a b = (a -> b, b -> Maybe a) | |
| -- As an example, suppose we want to check array binders [_, _, ..., _] for exhaustivity. | |
| -- We could introduce two constructors ArrNil and ArrCons, and require these constructors be | |
| -- binders in our language. | |
| data Array b = ArrNil | ArrCons b b deriving (Show) |
| {-# LANGUAGE FunctionalDependencies, DataKinds, GADTs, PolyKinds, KindSignatures, MultiParamTypeClasses #-} | |
| module Main where | |
| import Data.Monoid | |
| import Prelude (Maybe(..)) | |
| import qualified Prelude as P | |
| class Category (arr :: k -> k -> *) where |
| module Main where | |
| import qualified Prelude as P | |
| import Debug.Trace | |
| class Arithmetic lang where | |
| (+) :: lang Number -> lang Number -> lang Number | |
| (-) :: lang Number -> lang Number -> lang Number | |
| (*) :: lang Number -> lang Number -> lang Number | |
| (/) :: lang Number -> lang Number -> lang Number |
| module Main where | |
| main = Debug.Trace.trace ("module Main where\n\n" ++ code ++ "\n where code = \"\"\"" ++ code ++ "\"\"\"") | |
| where code = """main = Debug.Trace.trace ("module Main where\n\n" ++ code ++ "\n where code = \"\"\"" ++ code ++ "\"\"\"")""" |
| module Main where | |
| import Debug.Trace | |
| import Data.Tuple | |
| import Data.Either | |
| import Data.Lazy | |
| class Memo a where | |
| memo :: forall r. (a -> r) -> a -> Lazy r |
| {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-} | |
| module Main where | |
| import Test.QuickCheck | |
| class Arbiter f r where | |
| arbiter :: f -> Gen r | |
| instance Arbiter r r where |
This blog post series has moved here.
You might also be interested in the 2016 version.
| module Main where | |
| import Data.Maybe (fromMaybe) | |
| import Control.Monad (liftM, liftM2) | |
| data Term | |
| = TmVar Int | |
| | TmSkolem Int Int Int | |
| | TmPair Term Term |