Skip to content
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

#97, make sure OneofSubfield generates well-typed code for non-Maybe #99

Merged
merged 1 commit into from
Apr 17, 2019

Conversation

ndmitchell
Copy link
Collaborator

Before the test case in #97 generated:

((Hs.coerce @(Hs.Int64)
   @(HsProtobuf.Signed (HsProtobuf.Fixed Hs.Int64)))
   (HsProtobuf.ForceEmit y))

Now it generates:

HsProtobuf.ForceEmit
    ((Hs.coerce @(Hs.Int64)
        @(HsProtobuf.Signed (HsProtobuf.Fixed Hs.Int64)))
    y)

I'm assuming the ForceEmit is important, and that seemed like the only sensible place to put it. But I was totally guessing... I welcome feedback!


xE <- (if isMaybe then id else fmap forceEmitE)
. wrapE ctxt options dpType
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using dimap would be nice here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't see how to use dimap at all. Any hints?

Copy link
Collaborator

@themattchan themattchan Apr 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, you're right -- I thought both the pre- and post- operations were enabled by isMaybe.

This might read better though:

let adapt | isMaybe = lmap wrapJust
          | otherwise = rmap (fmap forceEmitE)

xE <- adapt (wrapE ctxt options dpType) (HsVar (unqual_ "y"))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find that harder to read. I guess I'd usually (. wrapJust) and (fmap forceEmitE .) rather than lmap/rmap - and in this case I'm not sure it's clearer at all. But happy to go that way if you want.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that it would be better to consolidate the adjustments predicated on isMaybe, but on second thought the extra indirection obfuscates matters.

Copy link
Collaborator

@themattchan themattchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 (with changes)

As an aside, I think generating

((Hs.coerce @(Hs.Int64)
   @(HsProtobuf.ForceEmit (HsProtobuf.Signed (HsProtobuf.Fixed Hs.Int64))))
   y)

would be even nicer, but there isn't really a performance benefit and would complicate the wrapE machinery.

@ndmitchell
Copy link
Collaborator Author

Thanks for the review. Yep, I tried to do that coerce you mention first, but that requires adding ForceEmit to the type data type, which seemed to be not very clean.

@themattchan
Copy link
Collaborator

Thanks for the bug fix, @ndmitchell!

@themattchan themattchan merged commit dd01df7 into awakesecurity:master Apr 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants