1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-21 02:27:10 +03:00
mal/elm/step0_repl.elm
2017-06-20 17:23:00 +02:00

79 lines
1.2 KiB
Elm

port module Main exposing (..)
import IO exposing (..)
import Json.Decode exposing (decodeValue)
import Platform exposing (programWithFlags)
main : Program Flags Model Msg
main =
programWithFlags
{ init = init
, update = update
, subscriptions =
\model -> input (decodeValue decodeIO >> Input)
}
type alias Flags =
{ args : List String
}
type alias Model =
{ args : List String
}
type Msg
= Input (Result String IO)
init : Flags -> ( Model, Cmd Msg )
init flags =
( flags, readLine prompt )
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Input (Ok (LineRead (Just line))) ->
( model, writeLine (rep line) )
Input (Ok LineWritten) ->
( model, readLine prompt )
Input (Ok (LineRead Nothing)) ->
( model, Cmd.none )
Input (Ok _) ->
( model, Cmd.none )
Input (Err msg) ->
Debug.crash msg ( model, Cmd.none )
prompt : String
prompt =
"user> "
read : String -> String
read ast =
ast
eval : String -> String
eval ast =
ast
print : String -> String
print ast =
ast
rep : String -> String
rep =
read >> eval >> print