OCaml : How to get a parameter from a type? -


this simple can't find answer anywhere.

let's created new type student = string * int tuple of student's name , score on test.

then list of student passed function, , have find average score of class (or list).

let blah (class : student list) : float = match class [] -> []  | hd :: tl -> hd ?????? 

so start standard pattern matching, 1 element of list (aka student) how extract test score? feel it's obvious , elementary i've coded ints, strings, int lists, int list list, etc.. hd piece of information want.

you need more elaborate pattern:

match class | [] -> ... | (name, score) :: tl -> ... 

in cases can use fst , snd components of pair, matching gives cleaner code (in experience).


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -