functional programming - What causes this Standard-ML type error? -


I was trying to create a tail-repeat version of this very simple SML function:

  Funny suffix [] = [[]] | Suffix (x :: xs) = (x :: xs) :: suffix xs;  

In the meantime, I was using type annotation on parameters. This is revealed by the following code, and causes a type of error (given below), but if I simply remove the type of annotation, then SML accepts it without any problem, the whole function is signed to the same signature Gives up the simple task of the above.

Funny Prefix_tel xs = Funny Prefix_Helper [] acc = [] :: ACC | Suffixes_helper (x :: xs: 'a list) (acc:' b 'list) = suffix_helper xs ((x :: xs) :: ap) suffixes_helper xs [] Finally;

Error:

  $ sml typeerror.sml Standard ML New Jersey v110.71 [Created: Thursday September 17 16:48:42 200 9] [ Opening typeerror.sml] val suffix = FN: 'a list - & gt; 'A list list typeerror.sml: 17.81-17.93 Error: Operator and operation do not agree [Uband match] Operator domain:' A list * 'A list list Operand:' A list * 'B. List in expression: (x:: Xs) :: ACC TyperEresam: 16.13-17.94 Error: Do not agree to the type of rules [Umbound match] Rules of the earlier: 'A list *' Z list list - & gt; The 'Z list' list of this rule: 'A list *' B list - & gt; 'Rule in Y: (X :: Ax:' A list, ACC: 'B list) = & gt; (Suffixes_helper xs) ((x :: xs: :: ACC) /usr/local/smlnj-110.71/bin/sml: Fatal Error - Error with Unwanted Exception taken on 0 ../compiler/TopLevel/interact/evalloop Sml: 66.19-66.27  

Two errors are given. The latter seems less important here, there is no mismatch between the two sections of suffix. First of all I can not understand. I annotate to state that the first is the absolute 'a: list' type and the other is the absolute type 'b: list' . The type of Hindle-Milner should not be a guess algorithm, which is made from above the general integration, as I think, with the 'b: list' with 'a: list list , 'b --- & gt; 'A list'? Edit: A suggestion suggests that there may be something like that with the Type Information Algorithm that rejects infrared types, which in some sense type annotations I would think that such a rule only On the parameters and fully function, the annotation will apply. I do not know that this is correct. In any case, I tried to move type annotation on the function body, and I get the same error:

  fun suffixes_helper [] acc = [] :: ACC | Suffixes_helper (x :: xs) acc = suffixes_helper (xs: 'a list) ((x: xs :: :: ac:' b list);  

The error is now: Error message: expression barrier [UBOUND match] does not match expression ': A list list barrier: B list in expression: (x :: xs) :: ACC: 'B' list

I am not sure about SML, but F #, Another functional language gives a warning in such a situation. It may be hard, but it makes sense: If the programmer introduces an additional type variable 'B', and if 'B' type list should be, the function can not be generic like programmer, Reportable.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -