Skip to content

Instantly share code, notes, and snippets.

@lucasmoreiradev
Last active December 17, 2021 17:05
Show Gist options
  • Save lucasmoreiradev/c92946827e0b1cd6e084ce81ce2fdcb5 to your computer and use it in GitHub Desktop.
Save lucasmoreiradev/c92946827e0b1cd6e084ce81ce2fdcb5 to your computer and use it in GitHub Desktop.
(* OCaml *)
type person = {
name: string;
age: int;
}
let happy_birthday user = match user with
| Some person -> String.concat " " ["Happy Birthday"; person.name]
| None -> "Is not logged"
let lucas = {
name = "Lucas";
age = 28;
}
let option = Some lucas
let _ = happy_birthday option
// ReasonML
type person = {
name: string,
age: int,
};
let happy_birthday = user => {
switch (user) {
| Some(person) => "Happy birthday " ++ person.name
| None => "Please login first"
};
};
let user = Some({name: "Lucas", age: 28});
print_endline(happy_birthday(user));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment