gdritter repos gcct / 8997f0f
Finished Forth example Getty Ritter 10 years ago
1 changed file(s) with 28 addition(s) and 1 deletion(s). Collapse all Expand all
409409 get : Forth (a, b) -> a
410410 drop : Forth (a, b) -> Forth b
411411 swap : Forth (a, (b, c)) -> Forth (b, (a, c))
412 add : Forth (Int, (Int, c)) -> Forth (Int, c)
412 app : Forth (a, (b, c)) -> (a -> b -> d) -> Forth (d, c)
413413 \end{verbatim}
414414 }
415415
450450 \end{verbatim}
451451 }
452452
453 We have to create a helper function in order to create a value of this
454 type, which is the helper function \dualtt{push'}:
455
456 {\color{NavyBlue}
457 \begin{verbatim}
458 doPush : Forth a -> b -> Forth (b, a)
459 doPush s x = merge s' from
460 push s' <- doPush s'
461 get s' <- x
462 drop s' <- s
463 swap s' <- push (get s) (push x (drop s))
464 app s' <-
465 let doApp f = push (f x (get s)) (drop s)
466 in doApp
467 \end{verbatim}
468 }
469
470 And then we can create an actual value of type \dualtt{Forth ()}:
471
472 {\color{NavyBlue}
473 \begin{verbatim}
474 initialState : Forth ()
475 initialState = merge s'
476 push s' <- doPush s'
477 \end{verbatim}
478 }
479
453480 \end{document}