Comments (10)
Wrong library 🙂
But also, is that actually necessary? Couldn't you just make a Lazy (F a)
instance?
from purescript-control.
@safareli do you want something like this? https://pursuit.purescript.org/packages/purescript-call-by-name/1.0.0
from purescript-control.
@garyb let's take this example:
data ListT m a = ListT (m (StepT a (ListT m a )))
unListT (ListT m) = m
data StepT a x = Nil | Cons a x
with regular Lazy you have to do:
instance lLazy :: Lazy (m (StepT a (ListT m a))) => Lazy (ListT m a) where
defer f = ListT $ defer (f >>> unListT)
it's ugly and is getting worth when this function is used in some context and you have to add Lazy (m (StepT a (ListT m a)))
constraint which also means StepT
should Be exposed.
on the other hand,
class Lazy1 f where
defer1 :: forall a. (Unit -> f a) -> f a
instance lLazy1 :: Lazy1 m => Lazy1 (ListT m) where
defer1 f = ListT $ defer1 (f >>> unListT)
implementation body is same but you just have Lazy1 m
constraint and it's more manageable to actually use in user code later vs just Lazy (m (StepT a (ListT m a)))
(it's similar to other Eq1, Ord1, etc... types)
@davezuch I know that, it's just unpractical to use because of propagation of Lazy (m (StepT a (ListT m a)))
.
from purescript-control.
looks like it was already there but got removed
#15
from purescript-control.
for example if you can't implement something like this with just Lazy
you need Lazy1
as it's used in f ~> g
so this works:
module FreeApLazy where
import Prelude
import Control.Alternative (class Alternative)
import Control.Applicative.Free (FreeAp, foldFreeAp, liftFreeAp)
import Control.Lazy (class Lazy, defer)
import Data.Newtype (class Newtype, un)
newtype FreeApLazy f a = FreeApLazy (FreeAp (FreeApLazyF f) a)
data FreeApLazyF f a
= FreeApLazyF (Unit -> (FreeApLazy f a))
| FreeApLazyLifted (f a)
derive instance newtypeFreeApLazy :: Newtype (FreeApLazy f a) _
derive newtype instance altFunctor :: Functor (FreeApLazy f)
derive newtype instance altApply :: Apply (FreeApLazy f)
derive newtype instance altApplicative :: Applicative (FreeApLazy f)
instance altLazy :: Lazy (FreeApLazy f a) where defer = defer1
instance altLazy1 :: Lazy1 (FreeApLazy f) where defer1 = FreeApLazyF >>> liftFreeAp >>> FreeApLazy
liftApL :: forall f. f ~> FreeApLazy f
liftApL = FreeApLazyLifted >>> liftFreeAp >>> FreeApLazy
foldFreeApLazy :: forall f g a. Lazy1 g => Alternative g => (f ~> g) -> FreeApLazy f a -> g a
foldFreeApLazy f = un FreeApLazy >>> foldFreeAp case _ of
FreeApLazyF cont -> defer1 $ cont >>> foldFreeApLazy f
FreeApLazyLifted a -> f a
class Lazy1 f where
defer1 :: forall a. (Unit -> f a) -> f a
but this doesn't:
foldFreeApLazy :: forall f g a. Alternative g => (forall x. Lazy (g x) => f x -> g x) -> FreeApLazy f a -> g a
foldFreeApLazy f = un FreeApLazy >>> foldFreeAp case _ of
FreeApLazyF cont -> defer $ cont >>> foldFreeApLazy f
FreeApLazyLifted a -> f a
I'm getting No type class instance was found for Control.Lazy.Lazy (g2 a3)
from purescript-control.
Will we be implementing this change?
from purescript-control.
Since adding this would be a non-breaking change, I'd like to leave it until after the 0.14.0 dust settles, at least. There also doesn't appear to be much demand for it, which is an argument against including it in the core libraries.
from purescript-control.
Meaning, why can't this just be implemented outside of core as a separate lib?
Yeah, since this isn't breaking, then I'll ignore it for now.
from purescript-control.
Yes, I think things should not be included in the core libraries unless we expect them to get a decent amount of use.
from purescript-control.
This should be implemented outside of the core libraries.
from purescript-control.
Related Issues (20)
- Add (<$$>) HOT 2
- $> breaks operator symmetry HOT 28
- Include a class for `hoist`? HOT 10
- Unknown module Data.Functor Control.Category, Data.Unit, Prelude HOT 4
- Annihilation law of alternative has incorrect order? HOT 1
- Add MonadOr? HOT 2
- laws for Lazy HOT 2
- provide filter for Alternative and Monad? HOT 5
- Use fundeps for an intermediate representation in `defer` HOT 8
- Definition of `fix` lacks sharing HOT 1
- MonadZero and MonadPlus seem redundant? HOT 10
- purescript-control#^3.0.0 vs purescript-control#^4.0.0 HOT 1
- Lazy instance for `Effect`
- Deprecate MonadZero HOT 21
- The distributivity law for Alternative rules out effectful instances HOT 28
- Remove deprecated MonadZero instance (v0.15.0 PS)
- Update class hierarchy to remove mention of MonadZero
- Consider updating misleading Alt documentation HOT 2
- Proposal: Make <|> right associative HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purescript-control.