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 C16E97F20B for ; Fri, 8 Feb 2013 03:47:48 +0100 (CET) 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: Ap4EAGlkFFGFBoIF/2dsb2JhbAA8CcEGc4IfAQEEASccATUCAwsLRiE2BhOHfwMJBax8hEEChRQNTIkDB4wWgQWDYGGIZ4tlgViFcIVPhRODDw X-IPAS-Result: Ap4EAGlkFFGFBoIF/2dsb2JhbAA8CcEGc4IfAQEEASccATUCAwsLRiE2BhOHfwMJBax8hEEChRQNTIkDB4wWgQWDYGGIZ4tlgViFcIVPhRODDw X-IronPort-AV: E=Sophos;i="4.84,626,1355094000"; d="scan'208";a="1480075" 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; 08 Feb 2013 03:40:26 +0100 Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id B706C635E; Fri, 8 Feb 2013 11:47:42 +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 6AC0D3964; Fri, 8 Feb 2013 11:47:42 +0900 (JST) DomainKey-Signature: h=Received:Subject:Mime-Version:Content-Type: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 [192.168.1.212] (bsdserver10-alias1.math.nagoya-u.ac.jp [172.16.62.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTPSA id 2D30B394C; Fri, 8 Feb 2013 11:47:42 +0900 (JST) Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) Content-Type: text/plain; charset=iso-8859-1 From: Jacques Garrigue In-Reply-To: Date: Fri, 8 Feb 2013 11:47:59 +0900 Cc: Caml List Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Ashish Agarwal X-Mailer: Apple Mail (2.1499) Subject: Re: [Caml-list] use identity for default function On 2013/02/08, at 4:22, Ashish Agarwal wrote: > I'd like to implement >=20 > val foo : ?f:('a -> 'b) -> 'a -> 'b >=20 > where the default for f is identity. Is there now a way to do this with a= ll the new features of OCaml? This is an old request (about as old as optional arguments). The problem is clear enough: you want a different type when no argument is = passed. Interestingly, it would be possible to do that using GADTs: type (_,_) optional =3D | Override : 'a -> ('a,'b) optional | Default : ('a,'a) optional let foo : type a b. (a -> b, a -> a) optional -> a -> b =3D function | Override f -> f | Default -> fun x -> x Unfortunately, GADTs were not there when optional arguments were introduced. Also, there is the problem that the type gets more complicated. (But there could be some sugar to print identical types only once) Jacques Garrigue=