-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zip NP and NS to produce NP #11
Comments
Interesting. I'm willing to add it, yes. Just struggling with naming. Perhaps something like this: expand_NS :: forall xs f . SingI xs => NS (f -.-> f) xs -> NP (f -.-> f) xs
expand_NS ns = case sing :: Sing xs of
SCons -> case ns of
Z f -> f :* hpure (Fn id)
S ns' -> Fn id :* expand_NS ns'
expand_SOP :: forall xss f . SingI xss => SOP (f -.-> f) xss -> POP (f -.-> f) xss
expand_SOP (SOP sop) = case sing :: Sing xss of
SCons -> case sop of
Z np -> POP (np :* unPOP (hpure (Fn id)))
S sop' -> POP (hpure (Fn id) :* unPOP (expand_SOP (SOP sop')))
class (Prod (Prod h) ~ Prod h) => Expandable (h :: (k -> *) -> (l -> *)) where
hexpand :: SingI xs => h (f -.-> f) xs -> Prod h (f -.-> f) xs
instance Expandable NS where
hexpand = expand_NS
instance Expandable SOP where
hexpand = expand_SOP
mapSingle :: (SingI xs, Expandable h, HAp (Prod h)) => h (f -.-> f) xs -> Prod h f xs -> Prod h f xs
mapSingle ns np = hexpand ns `hap` np |
Looks good. |
Sorry, but I'm going to not include this in 0.2 just yet. I'm still planning to do this, though. I'm just still thinking about the |
Ok, no problem. |
@feuerbach Just looked at this again due to the mention in https://ro-che.info/articles/2015-07-26-better-yaml-parsing I think that
|
@feuerbach Ah no, my mistake. The result type is wrong. |
Are we looking for |
alternatively hApplyInj :: (forall a. f a -> g a -> g a) -> NS f xs -> NP g xs -> NP g xs |
Not sure this is the same thing at all but I have recently found use (in https://github.com/adamConnerSax/perConstructor-sop ) for:
which seems like it might of the same ilk, though not quite. I see why "Defaultable1 f" (I don't know what that is and googling is not helping but I can guess and it makes sense.) would be useful. Though the version I had use for was general in the f but required something like Maybe to compose with. Though perhaps (Maybe :.: f) is Defaultable1 (?) and then my case is essentially covered? I'm a beginner with generics-sop (and markdown!), so forgive me if this is not a useful contribution to the discussion. Adam |
@phadej I think generalizing past the function type makes sense. We could get around the need for an additional type class by explicitly passing in the default. Something like
(and similar functions for Then AFAICS, the function @adamConnerSax needs is just
|
After all this time, I've actually implemented this and made a PR (#33). Feedback welcome. |
@feuerbach I hope that the |
Yes, now the code is much simpler. Thanks! |
Here's an alternative generalization of
<*>
:Unless I'm missing something, it can't be implemented in terms of the existing combinators. If so, I suggest adding it under some name.
The text was updated successfully, but these errors were encountered: