z1naOK9nu8iY5A
z1naOK9nu8iY5A

Reputation: 893

Defining an interpreter for the free monad

In the purescript-free package, there is a code example defining this interpreter:

teletypeN :: forall eff. NaturalTransformation TeletypeF (Eff (console :: CONSOLE | eff))
teletypeN (PutStrLn s a) = const a <$> log s
teletypeN (GetLine k) = pure (k "fake input")

How can I define and run another interpreter where the return type is Array Int or State String Int?

Upvotes: 1

Views: 162

Answers (1)

gb.
gb.

Reputation: 4649

You can't interpret to a specific value, as interpreters are provided as natural transformations - forall a. f a -> g a. The a here can't be "touched" by the function that is doing the interpretation.

You could interpret to Array or State String, but the a will always be determined by the structure you're interpreting. If you know that you only want to interpret Free MyAlgebra Int -> Array Int then this will all work out anyway.

Upvotes: 4

Related Questions