Created
July 28, 2014 11:49
-
-
Save ddrone/2bed9b74f579aa7cb564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE FunctionalDependencies #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
module Typelevel where | |
import Prelude hiding (sum) | |
-- type-level natural numbers | |
data Zero = Zero | |
data Succ a = Succ a | |
class ToInt a where | |
toInt :: a -> Int | |
class Sum a b c | a b -> c, a c -> b where | |
instance Sum Zero b b where | |
instance Sum a b c => Sum (Succ a) b (Succ c) where | |
two = Succ (Succ Zero) | |
three = Succ two | |
sum :: Sum a b c => a -> b -> c | |
sum _ _ = undefined :: c | |
-- load this into ghci and input ":t sum two three" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment