Loeb in Purescript
module Loeb where | |
import Prelude | |
import Data.Lazy (Lazy, defer, force) | |
import Data.Array ((!!)) | |
import Data.Maybe (fromMaybe) | |
loeb :: ∀ f a. Functor f => f (f (Lazy a) -> a) -> f (Lazy a) | |
loeb x = go where go = map (\y -> defer (\_ -> y go)) x | |
arr :: Array (Array (Lazy Int) -> Int) | |
arr = [ const 1, f 0, f 1, f 2 ] | |
where f = \n -> (\x -> fromMaybe 0 (map ((add 1) <<< force) (x !! n))) | |
-- | Output: | |
-- | [(defer \_ -> 1),(defer \_ -> 2),(defer \_ -> 3),(defer \_ -> 4)] | |
run :: Array (Lazy Int) | |
run = loeb arr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment