Coder Social home page Coder Social logo

hkd's Introduction

hkd

Hackage

This package provides some types and utilities for working with the "higher-kinded data" pattern in Haskell.

Contact Information

Contributions and bug reports are welcome!

Please feel free to contact me through github or on the #haskell IRC channel on irc.freenode.net.

-Edward Kmett

hkd's People

Contributors

phadej avatar ryanglscott avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hkd's Issues

Possible to use with type families?

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.

Add FFunctorWithIndex (and possibly a class for constraints)

-- 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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.