This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
datatype mytype = | |
TwoInts of int * int | |
|Str of string | |
|Pizza | |
fun f(x: mytype) = | |
case x of | |
Pizza => 3 | |
|Str s => 8 | |
|TwoInts(i1,i2) => i1 + i2 | |
val a = Str "hi" | |
val b = Pizza | |
val c = TwoInts(2,3) | |
val d = f c | |
val e = f Pizza | |
(* output of program | |
use "datatypes.sml"; | |
[opening datatypes.sml] | |
datatype mytype = Pizza | Str of string | TwoInts of int * int | |
val f = fn : mytype -> int | |
val a = Str "hi" : mytype | |
val b = Pizza : mytype | |
val c = TwoInts (2,3) : mytype | |
val d = 5 : int | |
val e = 3 : int | |
val it = () : unit | |
*) |
No comments:
Post a Comment