Skip to content

Instantly share code, notes, and snippets.

@throughnothing

throughnothing/Loeb.purs

Last active Oct 8, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.