[ http://dev.sourcefabric.org/browse/LS-617?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=22944#action_22944 ]
David Baelde commented on LS-617: --------------------------------- The comparison with OCaml should be taken with care: the type systems differ when it comes to labels and optional arguments. In liquidsoap, if you take f of type (x:string)->string, then f() has the same type: it's still expecting its argument x after the empty partial application. Now if you take f : (?x:string)->string, then f() has type string. This means that we cannot allow the latter type to be a subtype of the first. (By the way, all this is discussed in more details in the JFLA paper.) So even with a type annotation, your example should not work. Still, it would be useful to have (more) type annotations (currently we only parse basic types such as source(1,0,0)) to be able to understand such examples. Can you develop a bit more the real example you have in mind? > We need type annotations.. > -------------------------- > > Key: LS-617 > URL: http://dev.sourcefabric.org/browse/LS-617 > Project: Liquidsoap > Issue Type: New Feature > Affects Versions: 1.0 > Reporter: Romain Beauxis > Priority: Blocker > > Here's why: > # def apply(f, x) = f(x=x) end;; > apply : (((x:'a)->'b),'a)->'b = <fun> > # def optional(~x="f") = "f" end;; > optional : (?x:string)->string = fun (~x="f") -> "f" > # apply(optional, "foo");; > At line 316, char -125: > this value has type > (?x:_)->_ (infered at line 316, char -139--110) > but it should be a subtype of (the type of the v > In OCaml: > # let apply f x = f ~x:x ;; > val apply : (x:'a -> 'b) -> 'a -> 'b = <fun> > # let optional ?(x="foo") = x;; > Warning 16: this optional argument cannot be erased. > val optional : ?x:string -> string = <fun> > # apply optional "gni";; > Error: This expression has type ?x:string -> string > but an expression was expected of type x:'a -> 'b > BUT: > # let apply (f : ?x:'a -> 'b) x = f ~x:x ;; > val apply : (?x:'a -> 'b) -> 'a -> 'b = <fun> > # apply optional "gni";; > - : string = "gni" > In case you're wondering, I have a much more useful example that cannot work > without that... -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://dev.sourcefabric.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira ------------------------------------------------------------------------------ For Developers, A Lot Can Happen In A Second. Boundary is the first to Know...and Tell You. Monitor Your Applications in Ultra-Fine Resolution. Try it FREE! http://p.sf.net/sfu/Boundary-d2dvs2 _______________________________________________ Savonet-devl mailing list Savonet-devl@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/savonet-devl