# Foldable for (,)

15 messages
Open this post in threaded view
|
Report Content as Inappropriate

## Foldable for (,)

 I've seen many threads, including the one going on now, about why we need to have: length (2,3) = 1 product (2,3) = 3 sum (2,3) = 3 or (True,False) = False but the justifications all go over my head. Is there a beginner-friendly explanation for why such seemingly unintuitive operations should be allowed by default? _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Foldable for (,)

 On Sun, Apr 23, 2017 at 08:21:34AM +0000, Jonathon Delgado wrote: > I've seen many threads, including the one going on now, about why we need > to have: > > length (2,3) = 1 > product (2,3) = 3 > sum (2,3) = 3 > or (True,False) = False > > but the justifications all go over my head. Is there a beginner-friendly > explanation for why such seemingly unintuitive operations should be > allowed by default? Hello Jonathon,     the proponents of `Foldable (a,)` see `(2,3)` not as a pair of 'equal' values, but as a value *and* an annotation, much like some other folks see Either as having a value (Right a) *or* an annotation (usually an error in the form of Left e). So to go back to your examples:     (2,3)      ^ ^      | +------------- I am the value      |      +--------------- I am an annotation (and since tuples arguments can                       be heterogeneous, I could be a String, a Bool,                       anything). If you agree with this paradigm, `length`, `sum` and friend become a bit less icky. I would prefer tuples to be unbiased, but this intuition helped me connect with the people on the other side of the line. Does this help? _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Foldable for (,)

Open this post in threaded view
|
Report Content as Inappropriate

## Re: Foldable for (,)

 On Sun, Apr 23, 2017 at 10:06:00AM +0000, Jonathon Delgado wrote: > If a tuple only has one value, why do functions for operating over sets > make sense at all? I can see from your explanations why the answers could > be considered correct (if a particular convention is assumed), but why > does the operation make sense at all? It seems like we're asking for the > length of a single value, its product, etc. I can only guess: consistency. Once you create an instance of `Foldable` you instantly get some functions "for free". Among those are foldMap, foldr etc. *and* sum, length and friends. I cannot see an occurrence where writing `length (x, y)` instead of 1 makes sense. _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Foldable for (,)

 In reply to this post by Jonathon Delgado So then the question becomes, why do tuples need Foldable if the functions it defines aren't useful? _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Foldable for (,)

 In reply to this post by Jonathon Delgado > So to go back to your examples: > >     (2,3) >      ^ ^ >      | +------------- I am the value >      | >      +--------------- I am an annotation (and since tuples arguments can >                       be heterogeneous, I could be a String, a Bool, >                       anything). > > If you agree with this paradigm, `length`, `sum` and friend become a > bit less icky. To me, "annotation" connotes auxiliary information--yet it will be the primary key when pairs are sorted. I would be more comfortable with the explanation if the field were referred to as an "identifier", or some similar term. Doug _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Foldable for (,)

 In reply to this post by Jonathon Delgado A tuple doesn't only have one value. forall a. ((,) a) only has one value. Fortunately, Haskell has a kind system so we can easily determine what length does. > :k Foldable Foldable :: (* -> *) -> Constraint Clearly then, if we see a program (length x) where x is a tuple, then we can easily determine that this a constant value 1. For the same reason if we see (length [[1,2,3], [4,5,6]]) and ask, is the length 2 or 6? It's clearly 2; just look at the kind of Foldable. I like types, and types of types. Join me. On 23/04/17 20:06, Jonathon Delgado wrote: > If a tuple only has one value, _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners signature.asc (499 bytes) Download Attachment
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Foldable for (,)

 On 04/23/2017 08:29 PM, Tony Morris wrote: > A tuple doesn't only have one value. forall a. ((,) a) only has one > value. Fortunately, Haskell has a kind system so we can easily determine > what length does. This all makes sense when you realize that Foldable is just the "Object" class from Visual Basic. There's only one sensible way to define a ToString() method on an arbitrary object; therefore it makes sense to provide that method by default, and to have it do the one thing it can do (print garbage). _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Foldable for (,)

 In reply to this post by Jonathon Delgado Tony Morris - please could you give a (practical) example of code where the a tuple could realistically be passed to length, but you don't know what the answer will be at compile time? Michael Orlitzky - everything in .NET has to descend from Object because of it's OO design. Why does tuple have to implement Foldable if it doesn't provide any useful functions? Thank you very much everyone in this thread for helping me understand! _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Foldable for (,)

 One thing that's been missed in this discussion is that constraints can propagate. Of course no one is wanting to pass something they know is a tuple into a function they know is length.  But a function that expects something Foldable might want to know length or sum, and it might be reasonable to call that function on a tuple. On Sun, Apr 23, 2017 at 11:52 PM, Jonathon Delgado <[hidden email]> wrote: > Tony Morris - please could you give a (practical) example of code where the a tuple could realistically be passed to length, but you don't know what the answer will be at compile time? > > Michael Orlitzky - everything in .NET has to descend from Object because of it's OO design. Why does tuple have to implement Foldable if it doesn't provide any useful functions? > > Thank you very much everyone in this thread for helping me understand! > _______________________________________________ > Beginners mailing list > [hidden email] > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners_______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Foldable for (,)

 In reply to this post by Jonathon Delgado I only know that the length of any forall a. ((,) a) is going to be one. When it is polymorphic, I don't know that it is ((,) a) although it might be at the call site, and so I don't know the length.On Mon, Apr 24, 2017 at 4:52 PM, Jonathon Delgado wrote:Tony Morris - please could you give a (practical) example of code where the a tuple could realistically be passed to length, but you don't know what the answer will be at compile time? Michael Orlitzky - everything in .NET has to descend from Object because of it's OO design. Why does tuple have to implement Foldable if it doesn't provide any useful functions? Thank you very much everyone in this thread for helping me understand! _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Foldable for (,)

 In reply to this post by Jonathon Delgado On 04/24/2017 02:52 AM, Jonathon Delgado wrote: > > Michael Orlitzky - everything in .NET has to descend from Object > because of it's OO design. Why does tuple have to implement Foldable > if it doesn't provide any useful functions? > That was sarcasm =P I agree with you. _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Foldable for (,)

Open this post in threaded view
|
Report Content as Inappropriate