Skip to content

Instantly share code, notes, and snippets.

@reidev275
Created January 25, 2019 12:37
Show Gist options
  • Save reidev275/0e6a7d2379bb1f142b63934700352147 to your computer and use it in GitHub Desktop.
Save reidev275/0e6a7d2379bb1f142b63934700352147 to your computer and use it in GitHub Desktop.
import Control.Monad.Free (Free, liftF, foldFree)
import Effect (Effect)
import Effect.Console (log)
leftImpl ∷ State → State
leftImpl (State s) =
case s.direction of
North → State s { direction = West }
South → State s { direction = East }
East → State s { direction = North }
West → State s { direction = South }
interpretDsl ∷ Dsl ~> Effect
interpretDsl = foldFree morph
where
morph :: DslF ~> Effect
morph (Left state next) = do
log $ show s1 --write to console
pure $ next s1 --return our value inside of Effect
where
s1 = leftImpl state --get the new State of our rover
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment