Browse thread
When is a function polymorphic?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Fermin Reig <fermin.reig@c...> |
| Subject: | Re: [Caml-list] When is a function polymorphic? |
On Thu, 2005-03-31 at 13:04, Yaron Minsky wrote: > On Thu, 31 Mar 2005 17:32:23 +0900 (JST), Jacques Garrigue > > Is it so difficult to make the extra constructors explicit? > > I'd say there are two issues. The first is that it really can be a > pain for large variant types, particularly when the contents of those > types are changing during development, and you don't want the function > in question to depend on anything other than the particular variants > being modified. > [...] In my code, I try to avoid catchall '_' and 'x' patterns when possible. I end up with long 'or' patterns, such as | (A _ | B _ | C _ | ...) -> ... This style, while more verbose, has one advantage: if I later add a new constructor to my type, the exhaustiveness analysis warns me of all places where I should check. (In fact, this is most useful during development, since that's when type definitions change.) Regarding the typing of # function Some x -> Some () | None -> None;; # function Some x -> Some () | x -> x;; both Haskell and SML do the same as Ocaml, but, unlike Ocaml, neither gives a polymorphic type when using an 'as x' pattern. Fermin This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.