F# - signature file and implementation are not compatible: "The respective type parameter counts differ"

58 Views Asked by At

I am trying to write a library which implements an avl tree and I have organized all the code in a signature file and an implementation file.

the problem arises when the interpreter gets to this function:

//signature file:
...
type AvlT<'a,'b when 'a : equality and 'a : comparison and 'b : equality>
...
val searchEls  : src:'a -> avl:AvlT<'a,'b> ->  list<'a * 'b> 

//implementation file:
...
type AvlT<'a,'b when 'a : equality and 'a : comparison and 'b : equality> = 
    | Leaf 
    | Node of 'a * 'b * AvlT<'a,'b> * AvlT<'a,'b>
...

let searchEls  (src : 'a) (avl : AvlT<'a,'b>) = 
        let regEx = Regex (@"(?i)" + (string src))
        let check (str : string) (regEx : Regex) = (regEx.Match str).Success

        let rec srcEls aTree k = 
            match aTree with 
            | Leaf -> k []
            | Node (i, c , l , r) ->
                srcEls l (fun x -> srcEls r (fun y -> if check (string i) regEx then k (x @ ((i,c) :: y)) else k (x @ y))) 

        srcEls avl id

The reason I used Regex is that I need to return all the nodes that have a key which is like src (not just the node with a specific key) independently of upper and lower case (I don't kown if there are some "cleaner" ways to achieve that)

when I try to create the .dll an error and a warning show up:

/path/to/file/avl.fs(216,38): warning FS0064: This construct causes code to be less generic than indicated by the type annotations. The type variable 'a has been constrained to be type 'System.IComparable'.

/path/to/file/avl.fs(216,9): error FS0034: Module 'AVL.AvlTree' contains
    val searchEls<'b when 'b : equality> : src:System.IComparable -> avl:AvlT<System.IComparable,'b> -> (System.IComparable * 'b) list when 'b : equality but its signature specifies
    val searchEls<'a,'b when 'a : comparison and 'b : equality> : src:'a -> avl:AvlT<'a,'b> -> ('a * 'b) list when 'a : comparison and 'b : equality    
The respective type parameter counts differ

it looks like the interpretr is assuming the actual type of 'a instead of keeping it generic

0

There are 0 best solutions below