Sebastien
Sebastien

Reputation: 1328

Cant figure out what Error means and how to solve it

Here is the error code I have:

Characters 2004-2008
Error: The type constructor list expects 1 argument(s),
but is here applied to 0 argument(s)

Here is the Ocaml code I have written:

let createHuffmanTree (s:string) = match s with
    | "" -> Empty    (*Return an empty huffman tree ifstring is empty*)
    | _ -> let rec ca (l: list) (a: huffman) = match l with (*ERROR SHOULD BE ON THIS LINE*)
        | [] -> a (*If list is [] return the huffman tree*)
        | x,_ -> fold_left (ca) l level(leaf(x),a) (*For all the ellement of the list create a level and corresponding leaf*)
        in ca listFreq(explode(s)) Empty (*Start with an empty tree*)

Note:

explode take a string return it as a list of char ex:

# explode "Test";; 
- : char list = ['T'; 'e'; 's'; 't'] 

listFreq take the list from explode and return a pair of char * int being the char and the number of time it is found in the list return by explode ex:

# listeFreq (explode "AABCAABADBACAAB");; 
- : (char * int) list = [('A', 8); ('B', 4); ('C', 2); ('D', 1)] 

The Huffman Tree I am trying to create take a string (for exemple "AAABBC") and do this:

        level
|                   |
v                   v
leaf A            level
               |         |
               v         v
               leaf B    leaf C

The tree could also be Empty

Question: I have no idea how to solve the error code. Could someone point out a solution?

Upvotes: 0

Views: 243

Answers (1)

torbonde
torbonde

Reputation: 2459

I suppose that instead of (l: list), you should have something like (l: 'a list).

Upvotes: 2

Related Questions