Skip to content

Instantly share code, notes, and snippets.

@st98
Last active April 21, 2019 17:03
Show Gist options
  • Save st98/48245619bb8e3cb5cc74 to your computer and use it in GitHub Desktop.
Save st98/48245619bb8e3cb5cc74 to your computer and use it in GitHub Desktop.
OCaml 入門。Lesson 5。http://try.ocamlpro.com/
(* Step 4 *)
let xy =
let x = 'x' and y = 'y' in x :: [y]
let ab =
let a = 'a' and b = 'B' in a :: [Char.lowercase b]
let up = Char.uppercase in
let big_xy = List.map up xy and
big_ab = List.map up ab in
big_ab @ big_xy
(* Step 5 *)
if 1 + 2 = 3 then (
print_string "1 + 2 =\n";
print_string "3!!!!!!\n"
);;
if 1 + 2 = 3 then begin
print_string "1 + 2 =\n";
print_string "3!!!!!!\n"
end
(* Step 6 *)
(* double 3 + 2 = (double 3) + 2*)
let ten =
let double x = x+x in
double (3 + 2)
let hundred =
if true || false then (
print_string "May I help you?\n" ;
100
) else 0
let one =
let accum = ref (-54) in
for i = 1 to ten do accum := !accum + i done ;
!accum
one + match hundred with
| 42 -> (match ten with 10 -> 52 | _ -> 0)
| 100 -> (match ten with 10 -> 110 | _ -> 0)
| _ -> -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment