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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 1ED7C7EEEF for ; Thu, 21 May 2015 18:59:42 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of milanst@gmail.com) identity=pra; client-ip=209.85.212.178; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="milanst@gmail.com"; x-sender="milanst@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of milanst@gmail.com designates 209.85.212.178 as permitted sender) identity=mailfrom; client-ip=209.85.212.178; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="milanst@gmail.com"; x-sender="milanst@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f178.google.com) identity=helo; client-ip=209.85.212.178; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="milanst@gmail.com"; x-sender="postmaster@mail-wi0-f178.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0AXAQBUDl5VlLLUVdFchEIGgxm/cwmHUAKBQgc4FAEBAQEBAQERAQEBAQcLCwkfMIQjAQEEEhEEGQEbHQEDDAYFCw0CAiYCAiEBAREBBQEcBhMih3QBAxKhaD4xiz6Ba4J5mWUKGScNV4QbAQEBAQYBAQEBARcBBQ6BE4oZgk2COAeCaIFFBZwqgVeQHoU1EiOBDAmBBIMYPTGCRwEBAQ X-IPAS-Result: A0AXAQBUDl5VlLLUVdFchEIGgxm/cwmHUAKBQgc4FAEBAQEBAQERAQEBAQcLCwkfMIQjAQEEEhEEGQEbHQEDDAYFCw0CAiYCAiEBAREBBQEcBhMih3QBAxKhaD4xiz6Ba4J5mWUKGScNV4QbAQEBAQYBAQEBARcBBQ6BE4oZgk2COAeCaIFFBZwqgVeQHoU1EiOBDAmBBIMYPTGCRwEBAQ X-IronPort-AV: E=Sophos;i="5.13,470,1427752800"; d="scan'208";a="152450270" Received: from mail-wi0-f178.google.com ([209.85.212.178]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 21 May 2015 18:59:41 +0200 Received: by wicmx19 with SMTP id mx19so18950527wic.0 for ; Thu, 21 May 2015 09:59:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=WhUQ4essQp2QUMXaDFPQVh9ZhaWTUgdTe6nSs94klS4=; b=wGJbzeyqq9YG5rSZxtrX9Og0G27zeg8D2NG9xBB7Afg5CElGsuP+xC1qlSp6doJzwd bbFjhRIbUnurnEsVTRbCkTF7Jus+LtRjJlgJf39ltpCixLDPxvhHe1/eTPusDW6xq6oL h57d8k+ywLu0u2pDR3beeZS/iBn5dKa/u/fD1+3vdLi94kNfh83FBxOKmyQFiCrtwL4t mRLZVxz+dd3b+xf/ZxtA3KZPEuvnwqYWCjAf2glMHt8S2APCkg54b1hOapiKjYjDVWkM P2XWBCcG53yYk8flkoAtwKb6OmQi3nD2oY7r6cRg7xLupET9EMB4xb9P3F+uJtKUNacu jmCg== X-Received: by 10.194.82.167 with SMTP id j7mr7043493wjy.123.1432227581271; Thu, 21 May 2015 09:59:41 -0700 (PDT) MIME-Version: 1.0 Received: by 10.180.88.40 with HTTP; Thu, 21 May 2015 09:59:00 -0700 (PDT) In-Reply-To: References: From: =?UTF-8?Q?Milan_Stanojevi=C4=87?= Date: Thu, 21 May 2015 17:59:00 +0100 Message-ID: To: Trevor Smith Cc: "caml-list@inria.fr" Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] GADTs and JSON You must have 'a in the input if you want to return 'a json (at least a non-empty one). Same way you can't have function unit -> 'a list that returns a non-empty list. But it is probably not hard for you to create a witness type and have that in input. For example eg get:(map : map json) -> key:string -> 'a witness -> 'a json option You get None if key is not there or if it is not of the expected type. On Thu, May 21, 2015 at 5:42 PM, Trevor Smith wrote: > Hello, > > Is it possible to encode a recursive, heterogenous map and list > datastructure with GADTs? > > I want to encode JSON (there are already a couple of great libraries out > there so this is kind of an academic question). I would like to have > functions that can only take a JSON map type, for example to take a json map > and return a value. The key here is that the map can hold values of type > int,string and also maps. Is this possible? > > eg get : (map : map json) -> key:string -> 'a json > > Thank you. > > Trevor