Search code examples
functional-programmingsmlml

int -> ('a -> 'a)


I have a question that I came across studying SML. It requires the return type to be int -> (’a -> ’a). This is what I have done:

- fn x:int => fn y => y;
val it = fn : int -> 'a -> 'a

How can I make the return type to be int -> ('a -> 'a) where 'a -> 'a is in brackets? Any help would be appreciated, I have been trying it figure it out for hours and can't find anything related to it here or searching on Google.


Solution

  • A -> B -> C and A -> (B -> C) are the same type. The -> operator in types is right associative.

    By convention the type checker doesn't print redundant parentheses, so you'll never see int -> ('a -> 'a) printed for your code.

    You're already done. :-)