Guest User

Untitled

a guest
Jun 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. {-# LANGUAGE TypeSynonymInstances #-}
  2. {-# LANGUAGE MultiParamTypeClasses #-}
  3. {-# LANGUAGE FlexibleInstances #-}
  4. {-# LANGUAGE TypeFamilies #-}
  5.  
  6. module MyLang where
  7.  
  8. import Prelude (($),(.))
  9. import qualified Prelude as P
  10.  
  11. import Generic.Data.Bool
  12. import Generic.Data.Num
  13.  
  14. newtype MyLang a = ML {unML :: a}
  15.  
  16. type Bool = MyLang (TBool MyLang)
  17. type Number a = MyLang (TNum MyLang a)
  18. type Integer = Number P.Integer
  19.  
  20. instance BoolC MyLang where
  21. data TBool MyLang = MyTrue | MyFalse
  22. true = ML MyTrue
  23. false = ML MyFalse
  24. bool t _ (ML MyTrue) = t
  25. bool _ e (ML MyFalse) = e
  26.  
  27. instance (P.Num a) => Num MyLang a where
  28. data TNum MyLang a = MyNumber a
  29. fromInteger = ML . MyNumber . P.fromInteger
  30. abs = liftNum P.abs
  31. signum = liftNum P.signum
  32. (+) = liftNum2 (P.+)
  33. (-) = liftNum2 (P.-)
  34. (*) = liftNum2 (P.*)
  35. negate = liftNum P.negate
  36.  
  37. liftNum f (ML (MyNumber a)) = ML $ MyNumber $ f a
  38. liftNum2 f (ML (MyNumber a)) (ML (MyNumber b)) = ML $ MyNumber $ f a b
  39.  
  40. test :: Integer
  41. test = if' true (3 + 4) (4)
Add Comment
Please, Sign In to add comment