1 port module Main exposing (..)
3 import IO exposing (..)
4 import Json.Decode exposing (decodeValue)
5 import Platform exposing (programWithFlags)
6 import Types exposing (MalExpr(..))
7 import Reader exposing (readString)
8 import Printer exposing (printString)
9 import Utils exposing (maybeToList)
12 main : Program Flags Model Msg
18 \model -> input (decodeValue decodeIO >> Input)
33 = Input (Result String IO)
36 init : Flags -> ( Model, Cmd Msg )
38 ( flags, readLine prompt )
41 update : Msg -> Model -> ( Model, Cmd Msg )
44 Input (Ok (LineRead (Just line))) ->
47 ( model, writeLine out )
50 ( model, readLine prompt )
52 Input (Ok LineWritten) ->
53 ( model, readLine prompt )
55 Input (Ok (LineRead Nothing)) ->
59 Debug.crash msg ( model, Cmd.none )
67 {-| read can return three things:
69 Ok (Just expr) -> parsed okay
70 Ok Nothing -> empty string (only whitespace and/or comments)
71 Err msg -> parse error
74 read : String -> Result String (Maybe MalExpr)
79 eval : MalExpr -> MalExpr
84 print : MalExpr -> String
91 rep : String -> Maybe String
103 >> Result.map (Maybe.map (eval >> print))