[Haskell-cafe] Textbook example of instance Foldable ((,) a)

amindfv at mailbox.org amindfv at mailbox.org
Tue Nov 24 07:13:56 UTC 2020


On Mon, Nov 23, 2020 at 09:45:55PM +0100, Francesco Ariis wrote:
> Il 23 novembre 2020 alle 21:18 Sven Panne ha scritto:
> > Yes, you can think of (X, Y) as "Y with context X" or "a one-element
> > container with Y in it", but is this really what comes to your mind
> > first? I still highly doubt that. The Foldable-Traversable-in-Prelude
> > change was largely a good thing, but very surprising (and not really
> > needed) changes coming stealthily with it were only communicated when
> > it was already too late... :-/
> 
> I recall a long thread, with everyone top posting.
> This feature could have helped OP:
> 
>     https://gitlab.haskell.org/ghc/ghc/-/issues/11796
> 
> but unfortunately is still in design stage

Fwiw there is at least some strong user interest in this feature if anyone is thinking of working on it. I find myself checking on its progress pretty often, and would use it in our production codebase in a heartbeat.

The strongest motivation is bugs that I've caught during a refactor, where a type somewhere changes from e.g. [x] to (y, [x]), and deep in some function a call to length/maximum/whatever just starts returning useless values without a type error.

Consider, for example:

    do x <- getValuesForId "foo"
       when (length x > 1) $ fail "Unlikely condition: more than one value returned"
       ...

It may be a long time before you discover the 'when' clause will never fire because the type of x has changed to a 2-tuple. In the meantime, you've been doing something wrong with your conflicting data.

Tom


More information about the Haskell-Cafe mailing list