Browse thread
[Caml-list] tpyping question
[
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: | skaller <skaller@o...> |
| Subject: | Re: [Caml-list] tpyping question |
On Mon, 2003-08-11 at 15:18, Karl Zilles wrote: > skaller wrote: > > BTW: something I've needed is like this: > > > > type [`A of int * int | `B of int] > > let f x = match x with > > | `A (i,j) > > | `B i with j=0 -> .... > > (* ******** *) > > > > At the moment, I have to code this as: > > > > let f x = > > let g i j = ... in > > match x with > > | `A (i,j) -> g i j > > | `B i -> g i 0 > > > > delocalising the case handling code. > > > > Wouldn't it be more natural to write: > > let f x = > let (i,j) = match x with > | `A v -> v > | `B u -> (u,0) in > ... In reality there are 20 tags, not just the 2 shown. So I'd have to write: match x with | ..... | `A _ as y | `B _ as y -> let (i,j) = match y with `A v->v | `B u -> (u,0) in ... | ...... repeating the tags, In fact I do this sometimes, but it's also poor style repeating the tags. So I have 2 choices of poor style: repeat tags or delocalise handler, hence my suggestion, in which the handler is local and there's no repetition. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners