You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's say fg sometimes replaces the hello field in a record.
I can define
f:: (A->MaybeA) ->B->B
f p b = to (fg p (from b))
Most of the time, that's just dandy. But ... what if B is actually a newtype? The only way to force the application of p is to force the result of f. In hand-written code, we could write a special function for that:
importGHC.Tuple (Solo (..)) -- data Solo a = Solo a, for recent GHCfS:: (A->MaybeA) ->B->SoloB
We can do the same kind of thing generically:
f:: (A->MaybeA) ->RepB->Solo (RepB)
f p b =case fg p (from b) ofSolo rb ->Solo (to rb)
But there's an unfortunate effect: the calculation of to itself is suspended, so we hang on to an unneeded Z constructor in that thunk.
I suggest adding a method to Generic:
to#::Repa-> (#a#)
-- Custom GHC.Generics-based default goes here, and the default for `to` is replaced by-- to r = case to# r of (# a #) -> a
and a function
toA:: (Applicativef, Generica) =>Repa->fa
toA r | (# a #) <- to# r =pure a
The text was updated successfully, but these errors were encountered:
Suppose I have
Let's say
fg
sometimes replaces thehello
field in a record.I can define
Most of the time, that's just dandy. But ... what if
B
is actually a newtype? The only way to force the application ofp
is to force the result off
. In hand-written code, we could write a special function for that:We can do the same kind of thing generically:
But there's an unfortunate effect: the calculation of
to
itself is suspended, so we hang on to an unneededZ
constructor in that thunk.I suggest adding a method to
Generic
:and a function
The text was updated successfully, but these errors were encountered: