Я новичок в OCaml и не понимаю систему модулей в Ocaml.
module type Queue =
sig
type element
type queue
val enq: queue * element -> queue
end
module StringQ : Queue with type element = string =
struct
type element = string (* If I remove this it also doesn't work *)
type queue = element list
exception EMPTY_Q
let emptyq = []
let enq: queue * element -> queue =
fun arg ->
let (q, elem) = arg in
elem @ [q]
let rec deq: queue -> element * queue =
fun q ->
match q with
| [] -> raise EMPTY_Q
| x :: xs -> (x, xs)
end
Я получаю ошибку компиляции: This expression has type element list, but an expression was expected of type 'a list
А пока буду признателен за любые ссылки о модулях в Ocaml.
fun arg -> let (q, elem) = arg in ...
может быть простоfun (q, elem) -> ...
. Что еще более важно,@
имеет время выполнения, линейное по длине левого аргумента, поэтому вашеenq
не является постоянным временем (как я полагаю, вы хотели бы, чтобы это было). - person gsg   schedule 06.12.2013