You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
module Main
factorial : Int -> Int
factorial 0 = 1
factorial n = n * factorial (n - 1)
range : Int -> Int -> List Int
range from to = if from == to then [to] else from :: range (from + 1) to
moreThan : Int -> Int -> Maybe Int
moreThan lowLimit n = if n >= lowLimit then Just n else Nothing
main : IO ()
main = do
let hello = "Hello"
let world = "Мир"
-- long string to trigger GC
let longString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
putStrLn $ show $ range 1 10
putStrLn $ show $ split (== ' ') longString
putStrLn $ hello ++ strCons ' ' world
putStrLn $ show $ sum $ range 0 256
putStrLn $ show $ fromMaybe 42 $ moreThan 88 $ factorial 5
To build it run:
idris fact.idr --codegen wasm -o fact.wasm
For running compiled code you can use runner from rts/index.html. It contains some bootstrap code and simple tools for runtime introspection(print const section, stack, heap, fallback GC implementation, etc).
About
WebAssembly Code Generation Backend for Idris Compiler