home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / function / 1039 < prev    next >
Encoding:
Internet Message Format  |  1992-08-26  |  1.7 KB

  1. Path: sparky!uunet!mcsun!ieunet!swift.cs.tcd.ie!butrfeld
  2. From: butrfeld@swift.cs.tcd.ie
  3. Newsgroups: comp.lang.functional
  4. Subject: pairs vs. triples
  5. Message-ID: <1992Aug26.141437.8465@swift.cs.tcd.ie>
  6. Date: 26 Aug 92 14:14:37 GMT
  7. Organization: Computer Science Department, Trinity College Dublin
  8. Lines: 40
  9.  
  10.  
  11. Can anyone explain the following aspect of the Miranda and Haskell type
  12. systems that I find annoying ? Is there a theoretical reason for it ?
  13.  
  14. pairs, triples, quintuples, etc.. are _distinct_ types. In particular,
  15. (a,(b,c)) != ((a,b),c) != (a,b,c).
  16.  
  17. In a language called Sticks&Stones, based loosely on ML, that I have
  18. used, the following equality always held:
  19.  
  20. (a,(b,c)) = (a,b,c)
  21.  
  22. In other words a triple is simply a pair whose second item is a pair.
  23. Note that ((a,b),c) is not a triple.
  24.  
  25. Why is this convenient and the other approach annoying ?
  26.  
  27. Recently, while experimenting with Miranda, I called some standard
  28. function which returned a triple. I then found that I could not access
  29. the components of that triple from the interactive session, without
  30. writing a script to provide triple analysis functions. This is
  31. frustrating when trying to interactively explore the std environment.
  32. The functions "fst" and "snd" can only be applied to pairs.
  33.  
  34. In Sticks&Stones I could access the three elements of the triple (a,b,c)
  35. with the following calls to built-in functions:
  36.  
  37. fst (a,b,c)  --- returns a
  38. fst(snd(a,b,c)) --- returns b
  39. snd(snd(a,b,c)) --- returns c
  40.  
  41. Why is something like this not allowed in Miranda/Haskell ? Is it a
  42. result of the type inference schemes used here. Sticks&Stones is
  43. polymorphic, but does run-time type checks.
  44.  
  45. Awaiting your commments with interest,
  46.                     Andrew Butterfield
  47.  
  48. Dept. of Comp. Sci., Trinity College, Dublin 2, Ireland
  49. email: butrfeld@cs.tcd.ie
  50.