[ 
http://dev.sourcefabric.org/browse/LS-617?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=22947#action_22947
 ] 

David Baelde commented on LS-617:
---------------------------------

My bad. Subtyping is not allowed, but a type annotation would totally fix your 
problem (both the simple one from the original description, and the real 
problem). Basically, you would do:

def apply(f:(?x:'a)->'a,x) = f(x=x) end
# then you can pass a function with optional x to apply

def foo(~data,~headers,~uri,response:(?code:int,string)->string) = ... end
# then you can pass the good response function to that foo

> 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: Important
>
> 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

Répondre à