Created
January 8, 2016 03:47
-
-
Save deadfoxygrandpa/ad43d8dade00095ae92d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main (..) where | |
import Automaton | |
import Dict | |
import Graphics.Element exposing (show) | |
main = | |
Automaton.step 5 factorialAutomaton |> snd |> show | |
type alias State = | |
Dict.Dict Int Int | |
factorialAutomaton : Automaton.Automaton Int Int | |
factorialAutomaton = | |
let | |
factorial : Int -> State -> ( Int, State ) | |
factorial i state = | |
case Dict.get i state of | |
Just n -> | |
( n, state ) | |
Nothing -> | |
let | |
( n, state' ) = factorial (i - 1) state | |
in | |
( i * n, Dict.insert i n state' ) | |
in | |
Automaton.hiddenState (Dict.fromList [ ( 0, 1 ) ]) factorial |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment