Guest User

Untitled

a guest
Jun 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. {-# LANGUAGE OverlappingInstances #-}
  2. {-# LANGUAGE FlexibleInstances #-}
  3. {-# LANGUAGE MultiParamTypeClasses #-}
  4. {-# LANGUAGE GADTs #-}
  5.  
  6. module MyLang where
  7.  
  8. import Prelude (Integer(..), Show(..),String(..))
  9. import qualified Prelude as P
  10.  
  11. import Generic.Data.Bool
  12. import Generic.Data.Num
  13.  
  14. data MyLang a where
  15. MLFalse :: MyLang Bool
  16. MLTrue :: MyLang Bool
  17. MLValue :: a -> MyLang a
  18.  
  19. instance BoolC MyLang where
  20. false = MLFalse
  21. true = MLTrue
  22. bool t _ MLTrue = t
  23. bool _ e MLFalse = e
  24.  
  25. instance Num MyLang Integer where
  26. fromInteger = MLValue
  27. (MLValue a) + (MLValue b) = MLValue (a P.+ b)
  28. (MLValue a) - (MLValue b) = MLValue (a P.- b)
  29. (MLValue a) * (MLValue b) = MLValue (a P.* b)
  30.  
  31. test :: MyLang Integer
  32. test = if' true (3 + 4) (4)
Add Comment
Please, Sign In to add comment