0
  funcexpr:  /* This is a function: arguments -> string list */
   LPAREN HEAD arguments RPAREN                     { let head a = [List.hd (List.hd a)] in head << $3 }
 | LPAREN REAR arguments RPAREN                     { let rear b = List.tl (List.hd b) in rear << $3 }
 | LPAREN ERECT arguments RPAREN                    { let erect c = List.append (List.hd c) (List.hd (List.tl c)) in erect << $3 }
   ;
 arguments:  /* This is a list of functions */
   PARAM                                            { let func p = p in func }
 | funcexpr                                         { [$1] }
 | arguments arguments                              { List.append $1 $2 }

Returns an error: Error: This expression has type string list -> string list but an expression was expected of type string list -> string list list Type string is not compatible with type string list

I think that we need to somehow put func into a list, but every way I've tried doesn't seem to work! Any help appreciated..

2 Answers2

1

My suggestion is that you change

let func p = p in func

To

[ let func p = p in func ]

or you could use the more compact:

[ fun p -> p ]

This is based on the observation that the other alternatives for arguments return a list but the first alternative doesn't.

Jeffrey Scofield
  • 65,646
  • 2
  • 72
  • 108
0

I assume you are trying to compose functions with the << operator you have defined elsewhere.

Unfortunately $3 does not represent a function but a list of functions, therefore you need to do something to $3 before composing the functions.