* [Caml-list] variant type
@ 2003-06-17 18:03 Ye Wu
2003-06-17 18:15 ` Owen Gunden
2003-06-18 8:12 ` Alex Romadinoff
0 siblings, 2 replies; 3+ messages in thread
From: Ye Wu @ 2003-06-17 18:03 UTC (permalink / raw)
To: caml-list
Could you please tell me why the following doesn't work?
type shape = Square of int * int * int
|Circle of float * float * float;;
let area s =
match s with
Square (_, _, d) -> d * d
|Circle (_, _, r) -> 3.14 *. r *. r;;
Regards,
Ye
-------------------
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] variant type
2003-06-17 18:03 [Caml-list] variant type Ye Wu
@ 2003-06-17 18:15 ` Owen Gunden
2003-06-18 8:12 ` Alex Romadinoff
1 sibling, 0 replies; 3+ messages in thread
From: Owen Gunden @ 2003-06-17 18:15 UTC (permalink / raw)
To: caml-list
On Tue, Jun 17, 2003 at 02:03:35PM -0400, Ye Wu wrote:
> Could you please tell me why the following doesn't work?
Sure.
> type shape = Square of int * int * int
> |Circle of float * float * float;;
> let area s =
> match s with
> Square (_, _, d) -> d * d
> |Circle (_, _, r) -> 3.14 *. r *. r;;
It's because the area function is not well-typed. If the area function is
operating on a Square it wants to return an int; if it's operating on a
Circle it wants to return a float. It can only return one type.
Owen
-------------------
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [Caml-list] variant type
2003-06-17 18:03 [Caml-list] variant type Ye Wu
2003-06-17 18:15 ` Owen Gunden
@ 2003-06-18 8:12 ` Alex Romadinoff
1 sibling, 0 replies; 3+ messages in thread
From: Alex Romadinoff @ 2003-06-18 8:12 UTC (permalink / raw)
To: 'Ye Wu', caml-list
Hi
Just think what is the type of your function?
shape -> int or shape -> float ????
Regards,
Alex
-----Original Message-----
From: owner-caml-list@pauillac.inria.fr
[mailto:owner-caml-list@pauillac.inria.fr] On Behalf Of Ye Wu
Sent: Tuesday, June 17, 2003 10:04 PM
To: caml-list@inria.fr
Subject: [Caml-list] variant type
Could you please tell me why the following doesn't work?
type shape = Square of int * int * int
|Circle of float * float * float;;
let area s =
match s with
Square (_, _, d) -> d * d
|Circle (_, _, r) -> 3.14 *. r *. r;;
Regards,
Ye
-------------------
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
-------------------
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-06-18 8:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-17 18:03 [Caml-list] variant type Ye Wu
2003-06-17 18:15 ` Owen Gunden
2003-06-18 8:12 ` Alex Romadinoff
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).