-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.hs
More file actions
117 lines (66 loc) · 1.75 KB
/
Example.hs
File metadata and controls
117 lines (66 loc) · 1.75 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
module Example where
import Array
import YHC.Primitive
import Data.List
int0 = 0 :: Int
int1 = 1 :: Int
main0 xs = map head xs
main1 x = neq x
neq = not . eq
eq x = x == (0::Int)
main2 x y = neq2 (x::Int) y
neq2 x y = not (x == y)
main2_5 = case id f2_5 of
Just x -> x 1
Nothing -> 1
f2_5 = Just id
main3 xs = (a . b . c) xs
a x = x+(1::Int)
b x = x*(4::Int)
c x = x-(3::Int)
main4 x = even (x :: Int)
main4_5 = f4_5 (1::Int)
f4_5 = case id True of
True -> id
False -> id
main5 x = show (x :: Int)
main5_1 x = show (x :: Char)
main6 = show [()]
main6_1 = show (Just [()])
-- actually, this is UNRELATED to 6
main6_5 y = ma id y
ma x y = fst (x, ma x) y
-- NOTE: Cannot be firstified
data Wrap a = Wrap (Wrap a) | Value a
f a = f (Wrap a)
main7 = f (Value id)
main8 = putChar 'x'
main9 = read "1" :: Int
main10 = app1 (gen1 ())
app1 (x,y) = x (y int0)
gen1 () = (id,id)
main11 xs = app (gen xs)
app [] = []
app (x:xs) = x (1::Int) : app xs
gen [] = []
gen (x:xs) = const x : gen xs
main12 = array (0,0) [(0::Int,0::Int)]
main13 = show (1 :: Double)
main14 :: [(Int,Int)] -> Vector Int -> IO ()
main14 ivs v = mapM_ (\(i,a)-> primUpdateVectorC i (_E a) v) ivs
main15 = (sequence2 [return 'a', return 'b']) :: IO String
sequence2 :: Monad m => [m a] -> m [a]
sequence2 [] = return []
sequence2 (c:cs) = do
x <- c
xs <- sequence2 cs
return (x:xs)
main16 = catch (putChar 'a') (\_ -> putChar 'b')
main17 s = lines' s id
where
lines' [] acc = [acc []]
lines' ('\n':s) acc = acc ['\n'] : lines' s id -- Unix
lines' (c:s) acc = lines' s (acc . (c:))
main18 s = sort (s :: [Int])
main19 xs = mapM putChar xs
main20 xs = mapM_ putChar xs