Thread View: comp.lang.functional
4 messages
4 total messages
Started by butrfeld
Wed, 26 Aug 1992 14:14
pairs vs. triples
Author: butrfeld
Date: Wed, 26 Aug 1992 14:14
Date: Wed, 26 Aug 1992 14:14
40 lines
1839 bytes
1839 bytes
Can anyone explain the following aspect of the Miranda and Haskell type systems that I find annoying ? Is there a theoretical reason for it ? pairs, triples, quintuples, etc.. are _distinct_ types. In particular, (a,(b,c)) != ((a,b),c) != (a,b,c). In a language called Sticks&Stones, based loosely on ML, that I have used, the following equality always held: (a,(b,c)) = (a,b,c) In other words a triple is simply a pair whose second item is a pair. Note that ((a,b),c) is not a triple. Why is this convenient and the other approach annoying ? Recently, while experimenting with Miranda, I called some standard function which returned a triple. I then found that I could not access the components of that triple from the interactive session, without writing a script to provide triple analysis functions. This is frustrating when trying to interactively explore the std environment. The functions "fst" and "snd" can only be applied to pairs. In Sticks&Stones I could access the three elements of the triple (a,b,c) with the following calls to built-in functions: fst (a,b,c) --- returns a fst(snd(a,b,c)) --- returns b snd(snd(a,b,c)) --- returns c Why is something like this not allowed in Miranda/Haskell ? Is it a result of the type inference schemes used here. Sticks&Stones is polymorphic, but does run-time type checks. Awaiting your commments with interest, Andrew Butterfield Dept. of Comp. Sci., Trinity College, Dublin 2, Ireland email: butrfeld@cs.tcd.ie
Re: pairs vs. triples
Author: Fergus James HENDERSON
Date: Wed, 26 Aug 1992 16:45
Date: Wed, 26 Aug 1992 16:45
25 lines
1609 bytes
1609 bytes
butrfeld@swift.cs.tcd.ie writes: >Can anyone explain the following aspect of the Miranda and Haskell type >systems that I find annoying ? Is there a theoretical reason for it ? > >pairs, triples, quintuples, etc.. are _distinct_ types. In particular, >(a,(b,c)) != ((a,b),c) != (a,b,c). A practical reason is to give the implementation freedom to implement triples etc. as efficiently as possible. Requiring (a,b,c) to be stored in the same manner as (a,(b,c)) might require an extra level of indirection (and type equivalence usually implies storage equivalence). Theoretically I see no reason why (a,b,c) should be required to be equal to say (a,(b,c)). That seems like implementation details to me. It's also very assymetric - you have to require either left-pairing or right-pairing, and there is no obvious reason to prefer one over the other. It makes perfect sense to me that (a,b,c) is quite simply not a pair! -- Fergus Henderson fjh@munta.cs.mu.OZ.AU This .signature virus is a self-referential statement that is true - but you will only be able to consistently believe it if you copy it to your own .signature file!
Re: pairs vs. triples
Author: Vincent Zweije
Date: Thu, 27 Aug 1992 06:28
Date: Thu, 27 Aug 1992 06:28
23 lines
1572 bytes
1572 bytes
Andrew Butterfield writes:
>Can anyone explain the following aspect of the Miranda and Haskell type
>systems that I find annoying ? Is there a theoretical reason for it ?
>pairs, triples, quintuples, etc.. are _distinct_ types. In particular,
>(a,(b,c)) != ((a,b),c) != (a,b,c).
Fergus James HENDERSON replies:
>Theoretically I see no reason why (a,b,c) should be required to be
>equal to say (a,(b,c)). That seems like implementation details to me.
>It's also very assymetric - you have to require either left-pairing
>or right-pairing, and there is no obvious reason to prefer one over the
>other. It makes perfect sense to me that (a,b,c) is quite simply not a
>pair!
Of course, it is also impossible to let ((a,b),c) = (a,(b,c)), unless
you want to end up having a nondeterministic language. For if a
function expecting a pair were applied to such a thing, you would never
know whether to match its argument with ((a,b),c) or (a,(b,c)).
Vincent.
Re: pairs vs. triples
Author: Andrew Koenig
Date: Fri, 28 Aug 1992 15:24
Date: Fri, 28 Aug 1992 15:24
24 lines
1560 bytes
1560 bytes
In article <1992Aug26.141437.8465@swift.cs.tcd.ie> butrfeld@swift.cs.tcd.ie writes: > In a language called Sticks&Stones, based loosely on ML, that I have > used, the following equality always held: > (a,(b,c)) = (a,b,c) > In other words a triple is simply a pair whose second item is a pair. > Note that ((a,b),c) is not a triple. It sounds like that language didn't allow triples at all, only pairs. It's certainly possible to do that, but that would certainly be less convenient in other ways. For example, in ML a pair is a special case of a more general record type that consists of name-value pairs known and checked at compile time. A pair is just a record whose components are named 1 and 2; a triple is a record with components named 1, 2, and 3, and so on. I don't see how to allow pairs and not triples with that kind of unified design, and that unification is truly elegant and makes all sorts of other things easier to understand. -- --Andrew Koenig ark@europa.att.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads