Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
AwesomePrelude example with associated data families
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
module MyLang where
import Prelude (($),(.))
import qualified Prelude as P
import Generic.Data.Bool
import Generic.Data.Num
newtype MyLang a = ML {unML :: a}
type Bool = MyLang (TBool MyLang)
type Number a = MyLang (TNum MyLang a)
type Integer = Number P.Integer
instance BoolC MyLang where
data TBool MyLang = MyTrue | MyFalse
true = ML MyTrue
false = ML MyFalse
bool t _ (ML MyTrue) = t
bool _ e (ML MyFalse) = e
instance (P.Num a) => Num MyLang a where
data TNum MyLang a = MyNumber a
fromInteger = ML . MyNumber . P.fromInteger
abs = liftNum P.abs
signum = liftNum P.signum
(+) = liftNum2 (P.+)
(-) = liftNum2 (P.-)
(*) = liftNum2 (P.*)
negate = liftNum P.negate
liftNum f (ML (MyNumber a)) = ML $ MyNumber $ f a
liftNum2 f (ML (MyNumber a)) (ML (MyNumber b)) = ML $ MyNumber $ f a b
test :: Integer
test = if' true (3 + 4) (4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.