Skip to content

Instantly share code, notes, and snippets.

@dullbananas
Last active April 26, 2020 17:08
Show Gist options
  • Save dullbananas/9528046b42f8f85893b03c5943e786ca to your computer and use it in GitHub Desktop.
Save dullbananas/9528046b42f8f85893b03c5943e786ca to your computer and use it in GitHub Desktop.
love - programming language
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 ++ ";"
module Util exporting
- factorial
- readLines
- print
- 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