Skip to content

[WIP] Lazy instance #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
"package.json"
],
"dependencies": {
"purescript-control": "matthewleon/purescript-control#lazy-function",
"purescript-monoid": "^3.0.0",
"purescript-prelude": "^3.0.0"
},
"devDependencies": {
"purescript-eff": "^3.1.0",
"purescript-console": "^3.0.0"
}
}
4 changes: 4 additions & 0 deletions src/Data/Maybe.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Prelude
import Control.Alt (class Alt)
import Control.Alternative (class Alternative)
import Control.Extend (class Extend)
import Control.Lazy (class Lazy, defer)
import Control.MonadZero (class MonadZero)
import Control.Plus (class Plus)

Expand Down Expand Up @@ -201,6 +202,9 @@ instance boundedMaybe :: Bounded a => Bounded (Maybe a) where
top = Just top
bottom = Nothing

instance lazyMaybe :: Lazy a => Lazy (Maybe a) where
defer f = ((map (defer <<< const)) <$> f) unit

-- | The `Show` instance allows `Maybe` values to be rendered as a string with
-- | `show` whenever there is an `Show` instance for the type the `Maybe`
-- | contains.
Expand Down
21 changes: 21 additions & 0 deletions test/Main.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Test.Main where

import Prelude
import Control.Lazy as Z
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, logShow)
import Data.Maybe (Maybe(..))

diverge :: forall a. a -> a
diverge = Z.fix id

{-
explosiveMaybe :: Maybe Unit
explosiveMaybe = Just diverge <*> Just unit
-}

deferredMaybeExplosion :: Maybe Unit
deferredMaybeExplosion = Z.defer \_ -> Just diverge <*> Just unit

main :: Eff (console :: CONSOLE) Unit
main = logShow deferredMaybeExplosion