Allan Jiang
Allan Jiang

Reputation: 11341

OCaml unbound variable

I am implementing an NFA with Ocaml and the compiler gives me an error at this line

module Nfa : NFA =
struct

type transition = int * char option * int
type nfa = int * int list * transition list

let make_nfa s fs ts = nfa (s, fs, ts);;

The error is at the last line where the compiler says Error: Unbound value nfa

I am not sure what the problem is... Thank you

Upvotes: 0

Views: 3274

Answers (4)

newacct
newacct

Reputation: 122519

As others have mentioned, nfa is a synonym (like a typedef) for the tuple type int * int list * transition list.

You seem to want to use it like the constructor of an algebraic data type. If you want to do that, you would do something like this:

type nfa = Nfa of int * int list * transition list

let make_nfa s fs ts = Nfa (s, fs, ts)

But an algebraic data type with 1 constructor in this case is kind of a waste.

Upvotes: 0

efrey
efrey

Reputation: 399

You have nowhere declared the value nfa. You have only declared the type nfa.

As in

type nfa_type = int * int list * transitian list
let nfa = ( 1, [ 1; 2; 3 ], [x;y] )

edit: apologies for the typos I was in javascript mode

Upvotes: 3

Jeffrey Scofield
Jeffrey Scofield

Reputation: 66823

You're trying to use nfa as a constructor. But your type nfa doesn't define a constructor. It's just a synonym for a tuple type. So a value of the type would look like (3, [4], []).

Upvotes: 2

rkhayrov
rkhayrov

Reputation: 10260

transition and nfa are tuple type synonyms, not type constructors. Assuming you want make_nfa to be of type int -> int list -> transition list -> nfa, it would be simply

let make_nfa s fs ts = (s, fs, ts)

Upvotes: 3

Related Questions