Last active
April 26, 2020 17:08
-
-
Save dullbananas/9528046b42f8f85893b03c5943e786ca to your computer and use it in GitHub Desktop.
love - programming language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main exporting | |
- main | |
procedure main = | |
file : Io.stream <- loop getFilename: | |
case do Util.promptFileName: | |
Ok stream -> | |
Loop.exit getFilename stream | |
Err error -> | |
Util.print ( "Could not open file: " ++ Io.fmtError error ) | |
|> Loop.thenContinue | |
lines : List String <- do <| Util.readLines file | |
-- display a semicolon after each line of the file | |
for line in List.iterate lines: | |
do <| Util.print <| line ++ ";" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Util exporting | |
- factorial | |
- readLines | |
- promptFilename | |
function factorial : Int -> Int = | |
\n -> | |
case n: | |
_ if leftGreater n 0: | |
0 | |
0 or 1: | |
1 | |
_: | |
multiply | |
n | |
factorial n - 1 | |
function readLines : Io.Stream -> Effect ( List String ) = | |
Io.read -1 >> Effect.map ( String.split "\n" ) | |
function print : String -> Effect () = | |
String.append "\n" >> Io.write Io.stdout | |
function promptFilename : Effect ( Result Io.error Io.stream ) = | |
Io.write Io.stdout "Enter a filename: "promptF | |
|> Effect.then (\_ -> Io.read Io.stdin) | |
|> Effect.then Io.open |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment