Add and expose genericInject. (#940)

This is a counterpart to `genericAuto`, which is useful for dealing
with types coming from a library without orphan instances.
This commit is contained in:
quasicomputational 2019-05-06 04:21:50 +01:00 committed by Gabriel Gonzalez
parent 7d56778350
commit 48c73f3ef9

View File

@ -72,6 +72,7 @@ module Dhall
, Inject(..)
, inject
, genericInject
, RecordInputType(..)
, inputFieldWith
, inputField
@ -1140,6 +1141,17 @@ class Inject a where
inject :: Inject a => InputType a
inject = injectWith defaultInterpretOptions
{-| Use the default options for injecting a value, whose structure is
determined generically.
This can be used when you want to use 'Inject' on types that you don't
want to define orphan instances for.
-}
genericInject
:: (Generic a, GenericInject (Rep a)) => InputType a
genericInject
= contramap GHC.Generics.from (evalState (genericInjectWith defaultInterpretOptions) 1)
instance Inject Bool where
injectWith _ = InputType {..}
where