Skip to content

Commit bef2ba6

Browse files
committed
Fibonacci evaluation test
1 parent 7035386 commit bef2ba6

File tree

6 files changed

+173
-0
lines changed

6 files changed

+173
-0
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Golden.Fibonacci.Test where
2+
3+
import Prelude
4+
import Effect (Effect)
5+
import Effect.Console (logShow)
6+
7+
fib :: Int -> Int
8+
fib 0 = 0
9+
fib 1 = 1
10+
fib n = fib (n - 1) + fib (n - 2)
11+
12+
main :: Effect Unit
13+
main = logShow $ fib 32 -- 2178309
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"builtWith":"0.15.15","comments":[],"decls":[{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"bindType":"NonRec","expression":{"abstraction":{"annotation":{"meta":{"metaType":"IsForeign"},"sourceSpan":{"end":[10,22],"start":[10,21]}},"type":"Var","value":{"identifier":"add","moduleName":["Data","Semiring"]}},"annotation":{"meta":{"metaType":"IsSyntheticApp"},"sourceSpan":{"end":[10,34],"start":[10,9]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"type":"Var","value":{"identifier":"semiringInt","moduleName":["Data","Semiring"]}},"type":"App"},"identifier":"add"},{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"bindType":"NonRec","expression":{"abstraction":{"annotation":{"meta":{"metaType":"IsForeign"},"sourceSpan":{"end":[10,17],"start":[10,16]}},"type":"Var","value":{"identifier":"sub","moduleName":["Data","Ring"]}},"annotation":{"meta":{"metaType":"IsSyntheticApp"},"sourceSpan":{"end":[10,19],"start":[10,14]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"type":"Var","value":{"identifier":"ringInt","moduleName":["Data","Ring"]}},"type":"App"},"identifier":"sub"},{"bindType":"Rec","binds":[{"annotation":{"meta":null,"sourceSpan":{"end":[7,18],"start":[7,1]}},"expression":{"annotation":{"meta":null,"sourceSpan":{"end":[7,18],"start":[7,1]}},"argument":"v","body":{"annotation":{"meta":null,"sourceSpan":{"end":[7,18],"start":[7,1]}},"caseAlternatives":[{"binders":[{"annotation":{"meta":null,"sourceSpan":{"end":[8,6],"start":[8,5]}},"binderType":"LiteralBinder","literal":{"literalType":"IntLiteral","value":0}}],"expression":{"annotation":{"meta":null,"sourceSpan":{"end":[8,10],"start":[8,9]}},"type":"Literal","value":{"literalType":"IntLiteral","value":0}},"isGuarded":false},{"binders":[{"annotation":{"meta":null,"sourceSpan":{"end":[9,6],"start":[9,5]}},"binderType":"LiteralBinder","literal":{"literalType":"IntLiteral","value":1}}],"expression":{"annotation":{"meta":null,"sourceSpan":{"end":[9,10],"start":[9,9]}},"type":"Literal","value":{"literalType":"IntLiteral","value":1}},"isGuarded":false},{"binders":[{"annotation":{"meta":null,"sourceSpan":{"end":[10,6],"start":[10,5]}},"binderType":"VarBinder","identifier":"n"}],"expression":{"abstraction":{"abstraction":{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"type":"Var","value":{"identifier":"add","moduleName":["Golden","Fibonacci","Test"]}},"annotation":{"meta":null,"sourceSpan":{"end":[10,34],"start":[10,9]}},"argument":{"abstraction":{"annotation":{"meta":null,"sourceSpan":{"end":[10,12],"start":[10,9]}},"type":"Var","value":{"identifier":"fib","moduleName":["Golden","Fibonacci","Test"]}},"annotation":{"meta":null,"sourceSpan":{"end":[10,20],"start":[10,9]}},"argument":{"abstraction":{"abstraction":{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"type":"Var","value":{"identifier":"sub","moduleName":["Golden","Fibonacci","Test"]}},"annotation":{"meta":null,"sourceSpan":{"end":[10,19],"start":[10,14]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[10,15],"start":[10,14]}},"type":"Var","value":{"identifier":"n","sourcePos":[10,5]}},"type":"App"},"annotation":{"meta":null,"sourceSpan":{"end":[10,19],"start":[10,14]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[10,19],"start":[10,18]}},"type":"Literal","value":{"literalType":"IntLiteral","value":1}},"type":"App"},"type":"App"},"type":"App"},"annotation":{"meta":null,"sourceSpan":{"end":[10,34],"start":[10,9]}},"argument":{"abstraction":{"annotation":{"meta":null,"sourceSpan":{"end":[10,26],"start":[10,23]}},"type":"Var","value":{"identifier":"fib","moduleName":["Golden","Fibonacci","Test"]}},"annotation":{"meta":null,"sourceSpan":{"end":[10,34],"start":[10,23]}},"argument":{"abstraction":{"abstraction":{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"type":"Var","value":{"identifier":"sub","moduleName":["Golden","Fibonacci","Test"]}},"annotation":{"meta":null,"sourceSpan":{"end":[10,33],"start":[10,28]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[10,29],"start":[10,28]}},"type":"Var","value":{"identifier":"n","sourcePos":[10,5]}},"type":"App"},"annotation":{"meta":null,"sourceSpan":{"end":[10,33],"start":[10,28]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[10,33],"start":[10,32]}},"type":"Literal","value":{"literalType":"IntLiteral","value":2}},"type":"App"},"type":"App"},"type":"App"},"isGuarded":false}],"caseExpressions":[{"annotation":{"meta":null,"sourceSpan":{"end":[8,10],"start":[8,1]}},"type":"Var","value":{"identifier":"v","sourcePos":[0,0]}}],"type":"Case"},"type":"Abs"},"identifier":"fib"}]},{"annotation":{"meta":null,"sourceSpan":{"end":[12,20],"start":[12,1]}},"bindType":"NonRec","expression":{"abstraction":{"abstraction":{"annotation":{"meta":{"metaType":"IsForeign"},"sourceSpan":{"end":[13,15],"start":[13,8]}},"type":"Var","value":{"identifier":"logShow","moduleName":["Effect","Console"]}},"annotation":{"meta":{"metaType":"IsSyntheticApp"},"sourceSpan":{"end":[13,15],"start":[13,8]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"type":"Var","value":{"identifier":"showInt","moduleName":["Data","Show"]}},"type":"App"},"annotation":{"meta":null,"sourceSpan":{"end":[13,24],"start":[13,8]}},"argument":{"abstraction":{"annotation":{"meta":null,"sourceSpan":{"end":[13,21],"start":[13,18]}},"type":"Var","value":{"identifier":"fib","moduleName":["Golden","Fibonacci","Test"]}},"annotation":{"meta":null,"sourceSpan":{"end":[13,24],"start":[13,18]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[13,24],"start":[13,22]}},"type":"Literal","value":{"literalType":"IntLiteral","value":32}},"type":"App"},"type":"App"},"identifier":"main"}],"exports":["fib","main"],"foreign":[],"imports":[{"annotation":{"meta":null,"sourceSpan":{"end":[13,24],"start":[1,1]}},"moduleName":["Data","Function"]},{"annotation":{"meta":null,"sourceSpan":{"end":[13,24],"start":[1,1]}},"moduleName":["Data","Ring"]},{"annotation":{"meta":null,"sourceSpan":{"end":[13,24],"start":[1,1]}},"moduleName":["Data","Semiring"]},{"annotation":{"meta":null,"sourceSpan":{"end":[13,24],"start":[1,1]}},"moduleName":["Data","Show"]},{"annotation":{"meta":null,"sourceSpan":{"end":[4,23],"start":[4,1]}},"moduleName":["Effect"]},{"annotation":{"meta":null,"sourceSpan":{"end":[13,24],"start":[1,1]}},"moduleName":["Effect","Console"]},{"annotation":{"meta":null,"sourceSpan":{"end":[13,24],"start":[1,1]}},"moduleName":["Golden","Fibonacci","Test"]},{"annotation":{"meta":null,"sourceSpan":{"end":[3,15],"start":[3,1]}},"moduleName":["Prelude"]},{"annotation":{"meta":null,"sourceSpan":{"end":[13,24],"start":[1,1]}},"moduleName":["Prim"]}],"moduleName":["Golden","Fibonacci","Test"],"modulePath":"golden/Golden/Fibonacci/Test.purs","reExports":{},"sourceSpan":{"end":[13,24],"start":[1,1]}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
actual.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2178309
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
UberModule
2+
{ uberModuleBindings =
3+
[ Standalone
4+
( QName
5+
{ qnameModuleName = ModuleName "Data.Semiring", qnameName = Name "foreign"
6+
}, ForeignImport Nothing
7+
( ModuleName "Data.Semiring" ) ".spago/prelude/v7.2.0/src/Data/Semiring.purs"
8+
[ ( Nothing, Name "intAdd" ), ( Nothing, Name "intMul" ) ]
9+
), Standalone
10+
( QName
11+
{ qnameModuleName = ModuleName "Data.Semiring", qnameName = Name "semiringInt"
12+
}, LiteralObject Nothing
13+
[
14+
( PropName "add", ObjectProp ( Just Always )
15+
( Ref Nothing ( Imported ( ModuleName "Data.Semiring" ) ( Name "foreign" ) ) 0 )
16+
( PropName "intAdd" )
17+
),
18+
( PropName "zero", LiteralInt Nothing 0 ),
19+
( PropName "mul", ObjectProp ( Just Always )
20+
( Ref Nothing ( Imported ( ModuleName "Data.Semiring" ) ( Name "foreign" ) ) 0 )
21+
( PropName "intMul" )
22+
),
23+
( PropName "one", LiteralInt Nothing 1 )
24+
]
25+
), Standalone
26+
( QName
27+
{ qnameModuleName = ModuleName "Golden.Fibonacci.Test", qnameName = Name "sub"
28+
}, ObjectProp Nothing
29+
( LiteralObject Nothing
30+
[
31+
( PropName "sub", ObjectProp ( Just Always )
32+
( ForeignImport Nothing
33+
( ModuleName "Data.Ring" ) ".spago/prelude/v7.2.0/src/Data/Ring.purs"
34+
[ ( Nothing, Name "intSub" ) ]
35+
)
36+
( PropName "intSub" )
37+
),
38+
( PropName "Semiring0", Abs Nothing ( ParamUnused Nothing )
39+
( Ref Nothing ( Imported ( ModuleName "Data.Semiring" ) ( Name "semiringInt" ) ) 0 )
40+
)
41+
]
42+
)
43+
( PropName "sub" )
44+
), RecursiveGroup
45+
(
46+
( QName
47+
{ qnameModuleName = ModuleName "Golden.Fibonacci.Test", qnameName = Name "fib"
48+
}, Abs Nothing
49+
( ParamNamed Nothing ( Name "v" ) )
50+
( IfThenElse Nothing
51+
( Eq Nothing ( LiteralInt Nothing 0 ) ( Ref Nothing ( Local ( Name "v" ) ) 0 ) )
52+
( LiteralInt Nothing 0 )
53+
( IfThenElse Nothing
54+
( Eq Nothing ( LiteralInt Nothing 1 ) ( Ref Nothing ( Local ( Name "v" ) ) 0 ) )
55+
( LiteralInt Nothing 1 )
56+
( App Nothing
57+
( App Nothing
58+
( ObjectProp Nothing
59+
( Ref Nothing
60+
( Imported ( ModuleName "Data.Semiring" ) ( Name "semiringInt" ) ) 0
61+
)
62+
( PropName "add" )
63+
)
64+
( App Nothing
65+
( Ref Nothing
66+
( Imported ( ModuleName "Golden.Fibonacci.Test" ) ( Name "fib" ) ) 0
67+
)
68+
( App Nothing
69+
( App Nothing
70+
( Ref Nothing
71+
( Imported ( ModuleName "Golden.Fibonacci.Test" ) ( Name "sub" ) ) 0
72+
)
73+
( Ref Nothing ( Local ( Name "v" ) ) 0 )
74+
)
75+
( LiteralInt Nothing 1 )
76+
)
77+
)
78+
)
79+
( App Nothing
80+
( Ref Nothing
81+
( Imported ( ModuleName "Golden.Fibonacci.Test" ) ( Name "fib" ) ) 0
82+
)
83+
( App Nothing
84+
( App Nothing
85+
( Ref Nothing
86+
( Imported ( ModuleName "Golden.Fibonacci.Test" ) ( Name "sub" ) ) 0
87+
)
88+
( Ref Nothing ( Local ( Name "v" ) ) 0 )
89+
)
90+
( LiteralInt Nothing 2 )
91+
)
92+
)
93+
)
94+
)
95+
)
96+
) :| []
97+
)
98+
], uberModuleForeigns = [], uberModuleExports =
99+
[
100+
( Name "fib", Ref Nothing
101+
( Imported ( ModuleName "Golden.Fibonacci.Test" ) ( Name "fib" ) ) 0
102+
),
103+
( Name "main", App Nothing
104+
( ObjectProp ( Just Always )
105+
( ForeignImport Nothing
106+
( ModuleName "Effect.Console" ) ".spago/console/v6.1.0/src/Effect/Console.purs"
107+
[ ( Nothing, Name "log" ) ]
108+
)
109+
( PropName "log" )
110+
)
111+
( App Nothing
112+
( ObjectProp Nothing
113+
( LiteralObject Nothing
114+
[
115+
( PropName "show", ObjectProp ( Just Always )
116+
( ForeignImport Nothing
117+
( ModuleName "Data.Show" ) ".spago/prelude/v7.2.0/src/Data/Show.purs"
118+
[ ( Nothing, Name "showIntImpl" ) ]
119+
)
120+
( PropName "showIntImpl" )
121+
)
122+
]
123+
)
124+
( PropName "show" )
125+
)
126+
( App Nothing
127+
( Ref Nothing ( Imported ( ModuleName "Golden.Fibonacci.Test" ) ( Name "fib" ) ) 0 )
128+
( LiteralInt Nothing 32 )
129+
)
130+
)
131+
)
132+
]
133+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
local M = {}
2+
M.Data_Semiring_foreign = {
3+
intAdd = function(x) return function(y) return x + y end end,
4+
intMul = function(x) return function(y) return x * y end end
5+
}
6+
M.Data_Semiring_semiringInt = {
7+
add = M.Data_Semiring_foreign.intAdd,
8+
zero = 0,
9+
mul = M.Data_Semiring_foreign.intMul,
10+
one = 1
11+
}
12+
M.Golden_Fibonacci_Test_sub = function(x) return function(y) return x - y end end
13+
M.Golden_Fibonacci_Test_fib = function(v)
14+
if 0 == v then
15+
return 0
16+
else
17+
if 1 == v then
18+
return 1
19+
else
20+
return M.Data_Semiring_semiringInt.add(M.Golden_Fibonacci_Test_fib(M.Golden_Fibonacci_Test_sub(v)(1)))(M.Golden_Fibonacci_Test_fib(M.Golden_Fibonacci_Test_sub(v)(2)))
21+
end
22+
end
23+
end
24+
return (function(s) return function() print(s) end end)((function(n) return tostring(n) end)(M.Golden_Fibonacci_Test_fib(32)))()

0 commit comments

Comments
 (0)