Giter VIP home page Giter VIP logo

Comments (3)

phadej avatar phadej commented on June 13, 2024

there is a kind issue:

class Functor f => FunctorWithIndex i f | f -> i where -- f :: Type -> Type

-- but

type family Index (s :: Type) :: Type  -- s :: Type

so these cannot be easily the same.

Why one is TF and onther is FD, I don't know exactly. Index is used by bothIx and Contains classes, but that can be done with (anonymous) FD as well. (I like FDs more, but I guess i'm in minority in that: EDIT: IMHO non-associated open type family is the worst option).

from lens.

tysonzero avatar tysonzero commented on June 13, 2024

It's a little awkward with the kind mismatch as you have to use a somewhat dummy a in Index (f a), but I can't seem to find any major downsides?

class FunctorWithIndex f where
    imap :: (Index (f a) -> a -> b) -> f a -> f b

type instance Index [a] = Int 

instance FunctorWithIndex [] where
    imap f = zipWith f [0 ..]

I'm biased towards TypeFamilies, partly because they just feel more composable and functional, but also largely just because I think instance heads should be very simple and clearly decidable.

Various things I want to do that really aren't all that complicated require UndecidableInstances (and the currently incoherent FlexibleInstances) when done with FD's that don't require anything beyond TypeFamilies when done with TFs. Even outside the extensions, when glancing at them I can't quickly tell as a developer that the instances are reasonable without looking through the FD's at the class definition and mentally ignoring all the variables to the right of an arrow.

I also like being able to immediately tell that Index s is a function of s in a type signature, instead of having to look up the class definition or guess if s and i are related or what have you.

from lens.

phadej avatar phadej commented on June 13, 2024

but I can't seem to find any major downsides?

Index (f a) can depend on element type a. E.g. if you try to state imap f . imap g ≡ imap (\i -> f i . g i) law, you'd need forall a b. Index a ~ Index b like requirement.

This is matter of taste. I prefer FDs for this use case (and e.g. Each, where TFs would create a complete mess).

This is also be a major breaking change, affecting a lot of people for a what I would say a stylistic benefit. Not worth considering.

EDIT: indexed-traversable is also used by optics, and I used it in projects not using lens or optics (e.g. witherable).

from lens.

Related Issues (20)

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.