Copyright | (c) Tom Harding 2019 |
---|---|
License | MIT |
Maintainer | tom.harding@habito.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Documentation
class Build (structure :: Type) (f :: Type -> Type) (k :: Type) | f structure -> k where Source #
With many HKD applications, we're working with types like Maybe
where it
makes sense for us to start with mempty
and add values in as we go.
This isn't always the case, however: if all the component parts of our type
are gathered using some IO
action, we'd like to construct something like
HKD MyType IO
, and IO a
isn't a Monoid
for all types a
. When this
happens, we need to pass in our parameters when we build our structure.
The build
function lets us construct our type by passing explicit values
for each parameter:
>>>
:set -XDeriveGeneric -XTypeApplications
>>>
:{
data User = User { name :: String, age :: Int, likesDogs :: Bool } deriving Generic :}
>>>
:{
test :: _ test = build @User :} ... ... Found type wildcard ... ... standing for ...f [Char] -> f Int -> f Bool -> HKD User f... ...
Once we call the build
function, and indicate the type we want to build,
we are free to pick whichever f
we like and get to work!