From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 1BC1ABBAF for ; Tue, 23 Mar 2010 07:11:44 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApwBABb4p0uFBoIFl2dsb2JhbACbPQEBAQEBCBUHNawOjicBBIR9gyA X-IronPort-AV: E=Sophos;i="4.51,292,1267398000"; d="scan'208";a="55739052" Received: from rabbit.math.nagoya-u.ac.jp (HELO mailhost.math.nagoya-u.ac.jp) ([133.6.130.5]) by mail1-smtp-roc.national.inria.fr with ESMTP; 23 Mar 2010 07:11:43 +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 B1429B748; Tue, 23 Mar 2010 15:11:40 +0900 (JST) Received: from mailhost.math.nagoya-u.ac.jp (camel-172 [172.16.254.4]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 743AE88A5; Tue, 23 Mar 2010 15:11:40 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=math.nagoya-u.ac.jp; h= date:message-id:to:cc:subject:from:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=alpha; bh=RfJO7Lhs9ddbz0PEgQc5KEqMt8Y=; b=JS2fqZ3Xng07JV3z0ZfiklS9/XsY XGN0uCv/i+ztRXP3wDFjZcVN+Q5jNei4fZM9hy87kqoWempUSeN78AscF6xwJ189 FSXUV7CU8OM9zZB5oBBS+DOWqrEY79v3VrfkYHkCuPWmwnnavvtc+Wjpmr8Fb1V7 QAX4UvQ/MZEIRyQ= DomainKey-Signature: a=rsa-sha1; h=Received:Date:Message-Id:To:Cc:Subject:From:In-Reply-To:References:X-Mailer:Mime-Version:Content-Type:Content-Transfer-Encoding; b=VctklRS2yrK7w5h4Idwh9GRiiz/CK0Ut9zAMZN1an2oJVl56S3WXCP2Jeie+/nqauVC0wj3aULRWQJFxx4qfI0lUTvHJa/SyEplPbjBsRD287Hy3/0Ob0pO2g3mTtXjdxxPJN/IHjuR4xGhGfqprHBsJPR6Y/17grlHXgPawPaY=; c=nofws; d=math.nagoya-u.ac.jp; q=dns; s=alpha Received: from localhost (bsdserver02 [172.16.249.2]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 49C15889F; Tue, 23 Mar 2010 15:11:40 +0900 (JST) Date: Tue, 23 Mar 2010 15:11:40 +0900 (JST) Message-Id: <20100323.151140.125875815.garrigue@math.nagoya-u.ac.jp> To: kaspar.rohrer@gmail.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] Functions over polymorphic variants From: Jacques Garrigue In-Reply-To: References: X-Mailer: Mew version 6.3 on Emacs 22.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; variants:01 variants:01 ocaml:01 trivial:01 ocaml:01 combinators:01 polymorphic:01 polymorphic:01 abstract:01 rec:01 caml-list:01 functions:01 implemented:02 match:02 garrigue:03 From: Kaspar Rohrer > I am tinkering with streams of polymorphic variants at the > moment. One thing that I would like to do is to write a stream > transformer (not sure this is the correct terminology) that simply > drops certain values of an open polymorphic type, and have the type > of the function reflect this. Sorry, you can't. This is a design choice with ocaml polymorphic variants, that the row variable is kept hidden. This has the advantage of simplicity, but it makes impossible to abstract on the row variable itself, like you want here. > This is trivial with a closed polymorphic type: > > type abc = [`a | `b | `c] > > let transform (stream : [< `x | abc] Stream.t) : [> abc] Stream.t = > let rec fold () = > match Stream.next stream with > | `x -> Stream.slazy fold > | #abc as x -> Stream.icons x (Stream.slazy fold) > with > Stream.Failure -> Stream.sempty > in > fold () > > However, I fail to see how the same function could be implemented so it accepts an open polymorphic type as it's input. > I.e. is there a way to express something like this (which is not valid OCaml) > > let transform : [> `x | 'a] Stream.t -> [> 'a] Stream.t > > Does this even make sense? This makes sense, but would require a different type system. With ocaml, you must keep to closed types. This should be sufficient for concrete examples, but you cannot build polymorphic combinators. Note. In designing a type system where you would be able to express such "differential" types, poinder the problem: what is the type of transform composed with itself. Jacques Garrigue