user5357314
user5357314

Reputation: 31

OCaml type (int option list) list

I'm trying to make a type (int option list) list variable.

let blah :(int option list) list = [Some 30 ; Some 77] :: [Some 2 ; Some 3] ;;

However, this does not type check. I guess I'm just really lost on the syntax.

Upvotes: 1

Views: 2059

Answers (1)

gsg
gsg

Reputation: 9377

You almost got it:

let blah : (int option list) list = [Some 30 ; Some 77]::[[Some 2] ; [Some 3]]

Or, more readably:

let blah = [[Some 30; Some 77]; [Some 2]; [Some 3]]

The type problem is in the application of ::: you have different types for the left hand side and the elements of the right hand side.

Upvotes: 6

Related Questions