home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!ieunet!swift.cs.tcd.ie!butrfeld
- From: butrfeld@swift.cs.tcd.ie
- Newsgroups: comp.lang.functional
- Subject: pairs vs. triples
- Message-ID: <1992Aug26.141437.8465@swift.cs.tcd.ie>
- Date: 26 Aug 92 14:14:37 GMT
- Organization: Computer Science Department, Trinity College Dublin
- Lines: 40
-
-
- 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
-