# File eval mode now relies on main function
To encourage organizing code in a way that helps in understanding, I have implemented the common idiom of requiring a `main` function. In tricu and other functional languages, it is usually placed near the top of the module. The evaluator gracefully handles the situation of passing multiple files where the intermediary "library" files do not have main functions.
This commit is contained in:
@ -488,8 +488,9 @@ fileEval = testGroup "File evaluation tests"
|
||||
res @?= Fork (Stem Leaf) Leaf
|
||||
|
||||
, testCase "Mapping and Equality" $ do
|
||||
res <- liftIO $ evaluateFileResult "./test/map.tri"
|
||||
res @?= Stem Leaf
|
||||
library <- liftIO $ evaluateFile "./lib/base.tri"
|
||||
fEnv <- liftIO $ evaluateFileWithContext library "./test/map.tri"
|
||||
(mainResult fEnv) @?= Stem Leaf
|
||||
|
||||
, testCase "Eval and decoding string" $ do
|
||||
library <- liftIO $ evaluateFile "./lib/base.tri"
|
||||
|
@ -2,7 +2,7 @@
|
||||
-- t (t t) (t (t t t))
|
||||
-- t (t t t) (t t)
|
||||
-- x = (\a : a)
|
||||
t (t t) t -- Fork (Stem Leaf) Leaf
|
||||
main = t (t t) t -- Fork (Stem Leaf) Leaf
|
||||
-- t t
|
||||
-- x
|
||||
-- x = (\a : a)
|
||||
|
@ -1 +1 @@
|
||||
t t t
|
||||
main = t t t
|
||||
|
24
test/map.tri
24
test/map.tri
@ -1,24 +1,2 @@
|
||||
false = t
|
||||
true = t t
|
||||
_ = t
|
||||
k = t t
|
||||
i = t (t k) t
|
||||
s = t (t (k t)) t
|
||||
m = s i i
|
||||
b = s (k s) k
|
||||
c = s (s (k s) (s (k k) s)) (k k)
|
||||
iC = (\a b c : s a (k c) b)
|
||||
yi = (\i : b m (c b (i m)))
|
||||
y = yi iC
|
||||
triage = (\a b c : t (t a b) c)
|
||||
pair = t
|
||||
matchList = (\oe oc : triage oe _ oc)
|
||||
lconcat = y (\self : matchList (\k : k) (\h r k : pair h (self r k)))
|
||||
hmap = y (\self : matchList (\f : t) (\hd tl f : pair (f hd) (self tl f)))
|
||||
map = (\f l : hmap l f)
|
||||
lAnd = triage (\x : false) (\_ x : x) (\_ _ x : x)
|
||||
lOr = triage (\x : x) (\_ _ : true) (\_ _ x : true)
|
||||
equal = y (\self : triage (triage true (\z : false) (\y z : false)) (\ax : triage false (self ax) (\y z : false)) (\ax ay : triage false (\z : false) (\bx by : lAnd (self ax bx) (self ay by))))
|
||||
|
||||
x = map (\i : lconcat "Successfully concatenated " i) [("two strings!")]
|
||||
equal x [("Successfully concatenated two strings!")]
|
||||
main = equal? x [("Successfully concatenated two strings!")]
|
||||
|
Reference in New Issue
Block a user