Skip to content

Instantly share code, notes, and snippets.

@alesya-h
Created December 8, 2012 23:26
Show Gist options
  • Save alesya-h/4242505 to your computer and use it in GitHub Desktop.
Save alesya-h/4242505 to your computer and use it in GitHub Desktop.
Suming boxes and temperature to get length
type length = int;;
type boxes = int;;
type temperature = int;;
let make_len x : length = x;;
let make_box x : boxes = x;;
let make_temp x : temperature = x;;
let sum_len (a:length) (b: length) : length = a+b;;
sum_len (make_box 5) (make_temp 10);;
@alesya-h
Copy link
Author

I was completely wrong about this. This have to be something like the following:

type length = Length of int;;
type boxes = Boxes of int;;
type temperature = Temperature of int;;
let make_len x : length = Length x;;
let make_box x : boxes = Boxes x;;
let make_temp x : temperature = Temperature x;;
let sum_len (Length a) (Length b) : length = Length (a + b);;
sum_len (make_box 5) (make_temp 10);;                 
Error: This expression has type boxes but an expression was expected of type
         length

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment