-
Notifications
You must be signed in to change notification settings - Fork 14
/
Sample.hs
32 lines (22 loc) · 821 Bytes
/
Sample.hs
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
-- sample for BLC ghc plugin (see BLC.hs)
module Sample where
data List a = Cons a (List a)
deriving Show
infixr `Cons`
data Digit = Zero | One
deriving Show
Zero `xor` x = x
One `xor` One = Zero
One `xor` Zero = One
f (Cons a xs@(Cons b _)) = xor a b `Cons` f xs
ts = One `Cons` Zero `Cons` Zero `Cons` f ts
mainLC _ = ts
{-
compiles to:
0101000110100001000001100001100000011000000001011001011111101110010111100000100000110011111111101111001011010001000010100011010000001010101100111100101110110000000001110000101100000100101111011100000000011000010110000011001011110111000000000100001011000001100101111011100000000011110000000000011110
-}
-- some code for testing that is ignored by the BLC plugin
toList :: List a -> [a]
toList (Cons x xs) = x : toList xs
main = do
print $ take 10 $ toList $ ts