purescript-profunctor icon indicating copy to clipboard operation
purescript-profunctor copied to clipboard

Impossible to create an instance of the Costrong class

Open yukikurage opened this issue 2 years ago • 0 comments

The reason that Function and other types cannot be an instance of Costrong is that PureScript is a strict evaluation.

unfirst :: forall a b c. p (Tuple a c) (Tuple b c) -> p a b

That is, when we want to loop over c, it is impossible to set the initial value of c

How to modify it may be debatable, but I found the following solution

unfirstLazy :: forall a b c. Lazy c => p (Tuple a c) (Tuple b c) -> p a b
unfirstLazy f a = fst $ f $ Tuple a $ go
  where
  go = snd $ f $ Tuple a $ defer \_ -> go

Also, since this is not "Co" Strong, it might be better to name the class differently, for example CostrongLazy, or create a new library.

Thanks to natefaubion for sharing this issue on PureScript discord server.

yukikurage avatar Oct 18 '22 05:10 yukikurage