English 中文(简体)
Ocaml Syntax Error
原标题:
  • 时间:2009-11-07 21:17:26
  •  标签:
  • syntax
  • ocaml

What s wrong with this code? I can t figure it out:

let parent  (rules : grammar) (symbol1 : string) (symbol2 : string) : (SymbolSet.t) = 
  try
    SymbolSet.singleton (getParent [symbol1; symbol2] rules)
  with
      Not_found -> SymbolSet.singleton "";;

let fundementalRule (set1 : SymbolSet) (set2 : SymbolSet) (rules : grammar) : (SymbolSet) =
  allpairs (parent rules) set1 set2;;    

  Characters 20-21:
  let fundementalRule (set1 : SymbolSet) (set2 : SymbolSet) (rules : grammar) : (SymbolSet) =
                      ^
Syntax error:  )  expected, the highlighted  (  might be unmatched

The parenthesis is matched. What then is causing this issue?

This is just fine:

let fundementalRule set1 set2 rules =
  allpairs (parent rules) set1 set2;;
问题回答

maybe the types should be SymbolSet.t instead of SymbolSet

What s on the line above it? I d be willing to bet that there is an unmatched paren somewhere before this code.

Update

My intuition is telling me that the error is here:

SymbolSet.singleton (getParent [symbol1; symbol2] rules)

I don t have any way to test this code, but I do get an error when I try to run this code:

# let foo arg1 listarg arg2 = ();;
val foo :  a ->  b ->  c -> unit = <fun>
# foo (1 [1; 2] 2);;
Error: This expression is not a function; it cannot be applied

I think that should be this:

SymbolSet.singleton getParent [symbol1; symbol2] rules




相关问题
ocamlc, module compilation

I wrote an app in ocaml. It consist of several modules: Util (util.ml) Work1 (work1.ml) -- open Util Work2 (work2.ml) -- open Util, too Main (main.ml) -- open all of them. When i compile its, using ...

How can I simplify this ocaml pattern-matching code?

I m writing a simple little ocaml program that reads an algebraic statement in from a file, parses it into an AST using ocamllex/ocamlyacc, reduces it, and then prints it. The part where I m reducing ...

How can I create a type with multiple parameters in OCaml?

I m trying to create a type that has multiple type parameters. I know how to make a type with one parameter: type a foo = a * int But I need to have two parameters, so that I can parameterize the ...

Hashtable indexed on several fields

I m currently programming an OCaml module defining a type corresponding to a CPU register. The interface of this module is the following : (* * Defines a type which represents a R3000 register. *) ...

Extending an existing type in OCaml

I ve been doing some OCaml programming lately to learn the language and to get more acquainted with functional programming. Recently, I ve started to think that I d like to be able to extend an ...

Ocaml Syntax Error

What s wrong with this code? I can t figure it out: let parent (rules : grammar) (symbol1 : string) (symbol2 : string) : (SymbolSet.t) = try SymbolSet.singleton (getParent [symbol1; symbol2] ...

热门标签