phadej / hkd Goto Github PK
View Code? Open in Web Editor NEW"higher-kinded data"
License: Other
"higher-kinded data"
License: Other
-- compare to lens' functor with index
class FFunctor f => FFunctorWithIndex i f | f -> i where
iffmap :: (forall x . i x -> a x -> b x) -> f a -> f b
This can be very useful for HKDs if the index type reveals something about the parameter (e.g. if the index type is a GADT or has a context). If the index type is (Dict1 c) then we can map assuming c for the foralled parameter. If the HKD applies specific types/type level values to its parameter, its index might be a GADT that allows switching on those types.
It may be better to leave off the fundep and allow multiple index types, or introduce another class for the specific case of i = Dict1 c
.
class FFunctor f => FFunctorSatisfies c f where
assuming :: (forall x . c x => a x -> b x) -> f a -> f b
-- ambiguous type, intended use is with c explicitly applied
-- assuming @Read (readMaybe . getConst)
-- :: FFunctorSatisfies Read t => t (Const String) -> t Maybe
Apologies in advance if this question doesn't make any sense. I just came across this library today. I typically use HKDs where the functor f
applies to every field and I usually use this type family trick so that I can construct the normal record without the functor:
type family HKD f a where
HKD Identity a = a
HKD f a = f a
I'm able to write something like this:
data MyForm f = MyForm
{ myForm_name :: f String,
myForm_age :: f Integer
}
deriving (Generic)
instance FFunctor MyForm where ffmap = ffmapDefault
instance FFoldable MyForm where ffoldMap = ffoldMapDefault
instance FTraversable MyForm where ftraverse = gftraverse
But I cannot write:
data MyForm f = MyForm
{ myForm_name :: HKD f String,
myForm_age :: HKD f Integer
}
Because it wants an instance of (GFTraversable2 (Curried (Yoneda m)) f g (K1 R (HKD f String)) (K1 R (HKD g String)))
. Maybe what I'm trying to do is nonsensical but I thought I'd run it by you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.