Code Monkey home page Code Monkey logo

Comments (10)

garyb avatar garyb commented on July 30, 2024

Wrong library 🙂

But also, is that actually necessary? Couldn't you just make a Lazy (F a) instance?

from purescript-control.

davezuch avatar davezuch commented on July 30, 2024

@safareli do you want something like this? https://pursuit.purescript.org/packages/purescript-call-by-name/1.0.0

from purescript-control.

safareli avatar safareli commented on July 30, 2024

@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.

safareli avatar safareli commented on July 30, 2024

looks like it was already there but got removed
#15

from purescript-control.

safareli avatar safareli commented on July 30, 2024

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.

JordanMartinez avatar JordanMartinez commented on July 30, 2024

Will we be implementing this change?

from purescript-control.

hdgarrood avatar hdgarrood commented on July 30, 2024

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.

JordanMartinez avatar JordanMartinez commented on July 30, 2024

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.

hdgarrood avatar hdgarrood commented on July 30, 2024

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.

JordanMartinez avatar JordanMartinez commented on July 30, 2024

This should be implemented outside of the core libraries.

from purescript-control.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.