-
Notifications
You must be signed in to change notification settings - Fork 2
/
std.snow
77 lines (59 loc) · 1.63 KB
/
std.snow
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
-- This file is use to test and see if the grammar is working
-- and to experemt with new language syntaxes
-- Names of snow tools
-- snow men -> maybe package manager
-- snow storm -> maybe package manager
-- snow flake -> debugger
-- enum Result ok err = Ok ok | Err err
--
-- Result.mapOk Ok(x) f = Ok (f x)
-- Result.mapOk Err(x) f = Err x
--
--
-- enum Option a = Some a | None
--
-- Option.map Some 0 f = Some (0)
-- Option.map Some x f = Some (f x)
-- Option.map None f = None
--
-- print <| Option.map (foo 10) λx -> x + 1
-- Some 11
-- foo x = Some x
-- enum Bool = True | False
-- `==` :> a -> a -> Bool
-- `==` x y = core::equal x y Bool::True Bool::False
-- `<=` :> a -> a -> Bool
-- `<=` x y = core::less_equal x y Bool::True Bool::False
-- `>=` :> a -> a -> Bool
-- `>=` x y = core::greater_equal x y Bool::True Bool::False
-- `>` :> a -> a -> Bool
-- `>` x y = core::greater x y Bool::True Bool::False
-- `<` :> a -> a -> Bool
-- `<` x y = core::less x y Bool::True Bool::False
-- isDigit c
-- : Char -> Bool
-- = c >= '0' and c <= '9'
strJoin sep arr
: String -> Array<String> -> String
= if (length arr) > 0
then (sep + (head arr)) + (strJoin sep (tail arr))
else ""
max x y
: Int -> Int -> Int
= if x > y then x else y
min x y
: Int -> Int -> Int
= if x < y then x else y
clamp low high input
: Int -> Int -> Int -> Int
= max low (min input high)
-- main : IO = print (clamp 1 10 5)
map f arr
-- : (a -> b) -> Array<a> -> Array<b>
= if length arr == 0
then []
else [f (head arr)] + map f (tail arr)
addOne x : Int -> Int = x + 1
-- main
-- : IO
-- = print (map [1,2,3] addOne) "\n"