I don't think andThen helps here?
This commit is contained in:
parent
48f6e78196
commit
dc065d1943
|
|
@ -1,6 +1,7 @@
|
||||||
module Joy exposing (doit)
|
module Joy exposing (doit)
|
||||||
|
|
||||||
import String exposing (replace, words)
|
import String exposing (replace, words)
|
||||||
|
import Result exposing (andThen)
|
||||||
|
|
||||||
|
|
||||||
type JoyType
|
type JoyType
|
||||||
|
|
@ -39,13 +40,12 @@ joy_eval symbol stack expression =
|
||||||
joy_add : (List JoyType) -> (List JoyType) -> Result String (List JoyType, List JoyType)
|
joy_add : (List JoyType) -> (List JoyType) -> Result String (List JoyType, List JoyType)
|
||||||
joy_add stack expression =
|
joy_add stack expression =
|
||||||
case pop_int(stack) of
|
case pop_int(stack) of
|
||||||
Err msg -> Err msg
|
|
||||||
Ok (a, s0) ->
|
Ok (a, s0) ->
|
||||||
case pop_int(s0) of
|
case pop_int(s0) of
|
||||||
Err msg -> Err msg
|
|
||||||
Ok (b, s1) ->
|
Ok (b, s1) ->
|
||||||
let c = a + b in
|
Ok ((push_int ((+) a b) s1), expression)
|
||||||
Ok ((push_int c s1), expression)
|
Err msg -> Err msg
|
||||||
|
Err msg -> Err msg
|
||||||
|
|
||||||
|
|
||||||
push_int : Int -> (List JoyType) -> (List JoyType)
|
push_int : Int -> (List JoyType) -> (List JoyType)
|
||||||
|
|
@ -63,6 +63,11 @@ pop_int stack =
|
||||||
_ ->
|
_ ->
|
||||||
Err "Not an integer."
|
Err "Not an integer."
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Printer
|
-- Printer
|
||||||
|
|
||||||
joyTermToString : JoyType -> String
|
joyTermToString : JoyType -> String
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue