Ergonomic language features and lib cleanup
+ let bindings + where bindings + do notation I explored enough of the alternative language design space and decided that we should commit fully to Lambda style. That means no more highly tacit/concatenative point-free/partial programs as default. We'll keep taking advantage of those capabilities when it makes sense, but the library will continue to see massive overhauls.
This commit is contained in:
46
lib/base.tri
46
lib/base.tri
@@ -1,18 +1,18 @@
|
||||
false = t
|
||||
_ = t
|
||||
true = t t
|
||||
id = a : a
|
||||
const = a b : a
|
||||
id a = a
|
||||
const a b = a
|
||||
pair = t
|
||||
if = cond then else : t (t else (t t then)) t cond
|
||||
if cond then else = t (t else (t t then)) t cond
|
||||
|
||||
y = ((mut wait fun : wait mut (x : fun (wait mut x)))
|
||||
(x : x x)
|
||||
(a0 a1 a2 : t (t a0) (t t a2) a1))
|
||||
|
||||
compose = f g x : f (g x)
|
||||
compose f g x = f (g x)
|
||||
|
||||
triage = leaf stem fork : t (t leaf stem) fork
|
||||
triage leaf stem fork = t (t leaf stem) fork
|
||||
test = triage "Leaf" (_ : "Stem") (_ _ : "Fork")
|
||||
|
||||
matchBool = (ot of : triage
|
||||
@@ -31,15 +31,17 @@ lOr = (triage
|
||||
(_ _ : true)
|
||||
(_ _ _ : true))
|
||||
|
||||
matchPair = a : triage _ _ a
|
||||
matchPair a = triage _ _ a
|
||||
|
||||
fst = p : matchPair (a b : a) p
|
||||
snd = p : matchPair (a b : b) p
|
||||
fst p = matchPair takeFirst p
|
||||
where takeFirst a b = a
|
||||
snd p = matchPair takeSecond p
|
||||
where takeSecond a b = b
|
||||
|
||||
resultIsOk = result :
|
||||
resultIsOk result =
|
||||
matchResult (err rest : false) (val rest : true) result
|
||||
|
||||
resultIsErr = result :
|
||||
resultIsErr result =
|
||||
matchResult (err rest : true) (val rest : false) result
|
||||
|
||||
not? = matchBool false true
|
||||
@@ -82,10 +84,10 @@ succ = y (self :
|
||||
(_ tail : t t (self tail))
|
||||
t))
|
||||
|
||||
ok = value rest : pair true (pair value rest)
|
||||
err = msg rest : pair false (pair msg rest)
|
||||
ok value rest = pair true (pair value rest)
|
||||
err msg rest = pair false (pair msg rest)
|
||||
|
||||
matchResult = (errCase okCase result :
|
||||
matchResult errCase okCase result =
|
||||
matchPair
|
||||
(tag payload :
|
||||
matchPair
|
||||
@@ -95,27 +97,27 @@ matchResult = (errCase okCase result :
|
||||
(errCase value rest)
|
||||
tag)
|
||||
payload)
|
||||
result)
|
||||
result
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- Maybe / Option type
|
||||
-- ---------------------------------------------------------------------------
|
||||
|
||||
nothing = t
|
||||
just = x : t x
|
||||
just x = t x
|
||||
|
||||
matchMaybe = (nothingCase justCase maybe :
|
||||
matchMaybe nothingCase justCase maybe =
|
||||
triage
|
||||
nothingCase
|
||||
justCase
|
||||
(_ _ : nothingCase)
|
||||
maybe)
|
||||
maybe
|
||||
|
||||
maybe = default f m : matchMaybe default f m
|
||||
maybeMap = f m : matchMaybe nothing (x : just (f x)) m
|
||||
maybeBind = m f : matchMaybe nothing f m
|
||||
maybeOr = default m : matchMaybe default id m
|
||||
maybe? = matchMaybe false (_ : true)
|
||||
maybe default f m = matchMaybe default f m
|
||||
maybeMap f m = matchMaybe nothing (x : just (f x)) m
|
||||
maybeBind m f = matchMaybe nothing f m
|
||||
maybeOr default m = matchMaybe default id m
|
||||
maybe? = matchMaybe false (_ : true)
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- Basic arithmetic
|
||||
|
||||
Reference in New Issue
Block a user