diff options
Diffstat (limited to 'src/Unlambda/Builtins.hs')
-rw-r--r-- | src/Unlambda/Builtins.hs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/Unlambda/Builtins.hs b/src/Unlambda/Builtins.hs new file mode 100644 index 0000000..bb054a1 --- /dev/null +++ b/src/Unlambda/Builtins.hs @@ -0,0 +1,70 @@ +module Unlambda.Builtins ( + k, + s, + i, + dot, + r, + d, + c, + e + ) where + + +import Control.Exception( Exception(..), throw ) + + + +data MyException = MyException { func :: a -> b } + deriving (Show, Eq) + +instance Exception MyException + + + +k :: a -> b -> a +k x y = x + + + +s :: (a -> b -> c) -> (a -> b) -> a -> c +s x y z = (x z) (y z) + + + +i :: a -> a +i = id + + + +class Void a where + v :: a -> r + +instance Void v => Void (a -> r) where + v x = v + + + +dot :: Char -> a -> IO a +dot ch f = putChar ch >> return f + + + +r :: a -> IO a +r f = putChar '\n' >> return f + + + +-- may not work as per unlambda lazy semantics +d :: (a -> b) -> (a -> b) +d x = (\y -> x y) + + + +c :: (a -> b) -> (a -> b) +c x = (`runCont` id) (callCC $ \cont -> x cont) + + + +e :: a -> b +e x = throw (MyException x) + |