public
Created

AwesomePrelude example

  • Download Gist
gistfile1.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE GADTs #-}
 
module MyLang where
 
import Prelude (Integer(..), Show(..),String(..))
import qualified Prelude as P
 
import Generic.Data.Bool
import Generic.Data.Num
 
data MyLang a where
MLFalse :: MyLang Bool
MLTrue :: MyLang Bool
MLValue :: a -> MyLang a
 
instance BoolC MyLang where
false = MLFalse
true = MLTrue
bool t _ MLTrue = t
bool _ e MLFalse = e
 
instance Num MyLang Integer where
fromInteger = MLValue
(MLValue a) + (MLValue b) = MLValue (a P.+ b)
(MLValue a) - (MLValue b) = MLValue (a P.- b)
(MLValue a) * (MLValue b) = MLValue (a P.* b)
 
test :: MyLang Integer
test = if' true (3 + 4) (4)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.