Skip to content

Instantly share code, notes, and snippets.

@throughnothing
Last active October 8, 2018 17:29
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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