instances for Lazy
matthewleon opened this issue · 10 comments
There should be instances for these classes for the Lazy data type from purescript-lazy.
Realizing this is far easier said than done due to the kinds involved.
How so? Lazy has kind Type -> Type, and Foldable and Traversable both expect something of kind Type -> Type, no?
Well, you can't do, say, Foldable a => Foldable (Lazy a), which is the most natural way of expressing an instance that comes to mind. You'd need some kind of higher-order Lazy that does something like (Type -> Type) -> (Type -> Type).
Good chance I'm missing something obvious here, though. Let me know.
Oh, I thought you were imagining an instance which would give you e.g. toList = pure <<< force.
Interesting. There is that. I'll give it a shot.
I'm not really seeing that instance... How it would work, or what its benefit would be.
On the other hand... Why not?
Yeah, I haven't really used the data type Lazy very much so I can't comment on its benefit. I think it can be defined as follows though:
instance Foldable Lazy where
foldr f z x = f (force x) z
foldl f z x = f z (force x)
foldMap f = f (force x)I'm thinking that these instances might be better off in purescript-lazy. Thoughts?
I'm thinking that these instances might be better off in purescript-lazy. Thoughts?
That makes sense to me.