ocaml - Why is this weakly polymorphic -
After
I'm starting to learn OCaml and was trying to do some practices:
# left xy = x ;; Wall left: 'a - & gt; 'B - & gt; 'A = & lt; Funny & gt; #before = list.fold_right left ;; Valve first: '_a list - & gt; '_a - & gt; '_a = & lt; Funny & gt; Why completely weak polymophistically first
This price restriction is first is not a value, it is a function app. To get a fully polarized version, use the Eta extension:
leave xy = x ;; Wall left: 'a - & gt; 'B - & gt; 'A = & lt; Funny & gt; # First A B = list.fold_right left a b ;; First Val: 'A List - & gt; 'A - & gt; 'a = & lt; Funny & gt; @ivg explains, this is a commonly asked OCaml question.
Update Here is a function that is unsafe for generalization:
#fx = ref x ;; val f: 'a - & gt; 'A ref = & lt; Funny & gt; # F [] ;; -: '_a list ref = {content = []} If you have the result type that play' a list referee you can make the code go wrong ( I tried to do it). Here is a partial application that is unsafe for generalization:
# gx = let z = ref x fun () -> Z ;; Val g: 'a - & gt; Unit - & gt; 'A ref = & lt; Funny & gt; # G [] ;; -: unit - & gt; '_a list ref = & lt; Funny & gt; If you type the result the entity that plays -> gt; 'A list ref you can wrong this code (i tried it).
Comments
Post a Comment