-
Notifications
You must be signed in to change notification settings - Fork 211
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
API to construct InputType
s for Record types.
#530
API to construct InputType
s for Record types.
#530
Conversation
…onstruct InputTypes for record types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just two small comments
src/Dhall.hs
Outdated
> injectProject :: InputType Project | ||
> injectProject = | ||
> inputRecord | ||
> ( adapt >$< inputField "name" (inject @Text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the type applications are not necessary since they should be inferred by the context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are right. And actually, given the way the API is written, they should either be inputFieldWith
or the second parameter should be dropped entirely. The example as written woudn't typecheck!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we have doctest
enabled on this module, so if you transform the example into a doctest then it will be checked 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might do that in a separate PR, as it would involve modifying the $setup block to bring the Project
type into scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's not urgent to do in this PR
src/Dhall.hs
Outdated
-} | ||
|
||
-- | Infix 'contramap' | ||
(>$<) :: Contravariant f => (a -> b) -> f b -> f a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized that the >$<
operator already exists in the contravariant
package:
http://hackage.haskell.org/package/contravariant-1.5/docs/Data-Functor-Contravariant.html
... so we can reuse that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can drop that definitiion and just rexport the contravariant definition. Give me a few minutes.
Can I bikeshed the naming here? We already have an |
@quasicomputational maybe we should use the calling them |
src/Dhall.hs
Outdated
(>*<) :: Divisible f => f a -> f b -> f (a, b) | ||
(>*<) = divided | ||
|
||
infixr 4 >*< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be infixl 4 >*<
to work properly with the >$<
exported from contravariant, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should still be infixr
if you want the tuple nesting to be (a, (b, c))
, but the precedence needs to be elevated to 5
@Gabriel439 does this need anything else before it can be merged? |
@eamsden: No, nothing needs to be done. I just thought you had additional changes planned, but if you think this is ready then I'll go ahead and merge |
Adds the
RecordInputType
type and associated functionsinputFieldWith
,inputField
, andinputRecord
.These
inputField{,With}
functions and theContravariant
andDivisible
operations createRecordInputType
values which describe how a Haskell record type may be encoded into a Dhall expression. TheinputRecord
function converts aRecordInputType
to anInputType
.An example (using the same type as the example for
RecordType
) is given in the documentation comment for `RecordInputType.See #525