From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id D5C7F7ED25 for ; Fri, 19 Jul 2013 08:59:53 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of garrigue@math.nagoya-u.ac.jp) identity=pra; client-ip=133.6.130.5; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="garrigue@math.nagoya-u.ac.jp"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of garrigue@math.nagoya-u.ac.jp) identity=mailfrom; client-ip=133.6.130.5; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="garrigue@math.nagoya-u.ac.jp"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mailhost.math.nagoya-u.ac.jp) identity=helo; client-ip=133.6.130.5; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="postmaster@mailhost.math.nagoya-u.ac.jp"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ai4EANHi6FGFBoIFdGdsb2JhbABRCcRRgSQOAQwVCDyCJAEBBAEnEwkBNQIDCwsOOFcGExqHcAWjWIRIAoVpiAAHjlSBCDMHgw5uiSmON5RuLQ X-IPAS-Result: Ai4EANHi6FGFBoIFdGdsb2JhbABRCcRRgSQOAQwVCDyCJAEBBAEnEwkBNQIDCwsOOFcGExqHcAWjWIRIAoVpiAAHjlSBCDMHgw5uiSmON5RuLQ X-IronPort-AV: E=Sophos;i="4.89,699,1367964000"; d="scan'208";a="21649900" Received: from rabbit.math.nagoya-u.ac.jp (HELO mailhost.math.nagoya-u.ac.jp) ([133.6.130.5]) by mail3-smtp-sop.national.inria.fr with ESMTP; 19 Jul 2013 08:59:51 +0200 Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id EFE0C6398; Fri, 19 Jul 2013 15:59:47 +0900 (JST) Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id C52D440D0; Fri, 19 Jul 2013 15:59:47 +0900 (JST) DomainKey-Signature: h=Received:Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=; c=nofws; d=math.nagoya-u.ac.jp; q=; s=alpha Received: from garrigue-mini.math.nagoya-u.ac.jp (garrigue-mini.math.nagoya-u.ac.jp [172.16.30.37]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 85FBE40CF; Fri, 19 Jul 2013 15:59:47 +0900 (JST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\)) From: Jacques Garrigue In-Reply-To: <000001ce83bf$879e6520$96db2f60$@metastack.com> Date: Fri, 19 Jul 2013 15:59:47 +0900 Cc: "OCaml List" Content-Transfer-Encoding: quoted-printable Message-Id: <37C2C45C-A317-408E-8545-4FD426E3C817@math.nagoya-u.ac.jp> References: <000001ce83bf$879e6520$96db2f60$@metastack.com> To: David Allsopp X-Mailer: Apple Mail (2.1508) Subject: Re: [Caml-list] GADT in an optional parameter On 2013/07/18, at 23:03, David Allsopp wrote: > I then wanted to try to make the first parameter optional, defaulting to = Exn > (so you'd get the vanilla behaviour of Map.find): >=20 > module StringMap =3D > struct > include Map.Make(String) >=20 > let find : type s t . ?mode:(s, t) wrap -> string -> s > Map.Make(String).t -> t =3D fun ?(mode =3D Exn) key map -> > match mode with > Exn -> > find key map > | Option -> > try > Some (find key map) > with Not_found -> None > end >=20 > But I get: This expression has type (s, s) wrap but an expression was > expected of type (s, t) wrap on the Exn default value. >=20 > Now, in my woolly way, I thought that the default value for an optional > parameter behaved /almost/ like syntactic sugar, but clearly not. Is ther= e a > way to annotate this to achieve what I'm after?=20 No, clearly no. Optional arguments have no impact on typing: the absence of an optional argument cannot force some extra equation. I agree this would be interesting, but then we would need a way to express it in the type. Otherwise, why would the user expect (s=3Dt) when there is = no argument, whereas there is no way to see what the default is? Something like: val find : ?mode:(('s,'t) wrap =3D Exn) -> string -> 's Map.Make(String).t= -> 't It would be good to see whether this has many applications. In the past, there were some request to be able to default to the identity = function. Jacques=