Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# 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)
Add Comment
Please, Sign In to add comment