Trying to compile
module F (M : sig
type t = [> `Foo ]
end) = struct
type t = [ M.t | `Bar ]
end
gets me
Error: A type variable is unbound in this type declaration.
In type [> `Foo ] as 'a the variable 'a is unbound
What am I doing wrong?
In OCaml, higher-order and polymorphic functions are powerful tools for code reuse. Higher-order functions are those functions that take other functions as arguments or return functions as results, while polymorphic functions are functions that act over values with many different types.
Polymorphism, as related to genomics, refers to the presence of two or more variant forms of a specific DNA sequence that can occur among different individuals or populations. The most common type of polymorphism involves variation at a single nucleotide (also called a single-nucleotide polymorphism, or SNP).
What are functors and why do we need them? A functor is a module that is parametrized by another module, just like a function is a value which is parametrized by other values, the arguments. It allows one to parametrize a type by a value, which is not possible directly in OCaml without functors.
:: means 2 camel humps, ' means 1 hump! – Nick Craver. Feb 27, 2010 at 12:09. Ok a decent comment: merd.sourceforge.net/pixel/language-study/… I don't use oCaml, but there's a full syntax list you my find useful, even if there's no real context to it.
type t = [> `Foo]
is invalid since [> `Foo]
is an open type and contains a type variable implicitly. The definition is rejected just as the following type definition is rejected since the RHS has a type variable which is not quantified in LHS:
type t = 'a list
You have to make it closed:
type t = [ `Foo ]
or quantify the type variable:
type 'a t = [> `Foo] as 'a
which is equivalent to
type 'a t = 'a constraint 'a = [> `Foo]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With