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 (printStr)
11 main : Program Flags Model Msg
17 \model -> input (decodeValue decodeIO >> Input)
32 = Input (Result String IO)
35 init : Flags -> ( Model, Cmd Msg )
37 ( flags, readLine prompt )
40 update : Msg -> Model -> ( Model, Cmd Msg )
43 Input (Ok (LineRead (Just line))) ->
46 ( model, writeLine out )
49 ( model, readLine prompt )
51 Input (Ok LineWritten) ->
52 ( model, readLine prompt )
54 Input (Ok (LineRead Nothing)) ->
58 Debug.crash "unexpected IO received: " io
61 Debug.crash msg ( model, Cmd.none )
69 {-| read can return three things:
71 Ok (Just expr) -> parsed okay
72 Ok Nothing -> empty string (only whitespace and/or comments)
73 Err msg -> parse error
76 read : String -> Result String (Maybe MalExpr)
81 eval : MalExpr -> MalExpr
86 print : MalExpr -> String
93 rep : String -> Maybe String
105 >> Result.map (Maybe.map (eval >> print))