Ocaml values ββdo not match parameterized type in module and signature
I'm trying to do one of the advanced exercises at http://okmij.org/ftp/tagless-final/nondet-effect.html#no-functor and replace the type int_t
with 'a repr
. While trying to do this, I am stuck on the following error:
Values do not match:
val cons : '_a repr -> '_a list_t -> '_a list_t
is not included in
val cons : 'a repr -> 'a list_t -> 'a list_t
my implementation cons
looks like
let cons: 'a repr -> 'a list_t -> 'a list_t =
liftm2 (fun h t -> h::t)
which is definitely of the correct type. Why are these apparently identical types incompatible?
Making a minimal example helped me solve the problem! I managed to reduce the bad case:
module type Test = sig
type 'a t
val id: 'a t -> 'a t
end
module TestT: Test = struct
type 'a t = 'a
let id_maker () x = x
let id: 'a t -> 'a t =
id_maker ()
end
which indicates that I am falling victim to value constraints . There's a similar problem in this other question , but I was misled by the module error message. I fixed the problem by going from
let cons: 'a repr -> 'a list_t -> 'a list_t =
liftm2 (fun h t -> h::t)
to
let cons: 'a repr -> 'a list_t -> 'a list_t =
fun h t -> liftm2 (fun h t -> h::t) h t