Comments (3)
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.
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.
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)
- Does not compile on GHC 9.2.2 (pre-release): Module ‘Data.Semigroup’ does not export ‘getOption’ HOT 2
- Add O(1) `Iso'`s for sets with map representations HOT 2
- `Bizarre` as a superclass of `IndexedComonadStore`?
- Compatibility with transformers-0.6 and mtl-2.3 HOT 12
- FYI: all dependencies should be GHC-9.4 compatible now HOT 2
- creately.com diagram template broken, blocks #828 HOT 2
- Expand tuple accessors to support 26-item tuples
- Add `Zoom` for `Control.Monad.Trans.WriterT.CPS` HOT 1
- Missing combinators for creating and consuming Fold1, and IndexedFold1 's
- Add a strict over? HOT 1
- Are state modifications supposed to be so lazy? HOT 1
- Dead link in description HOT 1
- No accessors are generated when using `NoFieldSelectors` to remove prefixes. HOT 3
- Splitting Ixed/At/Contains into their own package HOT 2
- Build failure with GHC-9.6, mtl-2.3.1 but transformers-0.5 HOT 12
- Negative Index onto Text type results in returning first element HOT 4
- Separate Plated into own package HOT 1
- Enable makeWrapped to work with data family instances HOT 1
- Change the link in github HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lens.