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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 6B5677F1C3 for ; Sat, 24 Nov 2012 19:35:26 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.223.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.223.182 as permitted sender) identity=mailfrom; client-ip=209.85.223.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ie0-f182.google.com) identity=helo; client-ip=209.85.223.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-ie0-f182.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlMDACASsVDRVd+2lGdsb2JhbAA7CYYoug0IFg4BAQEBCQkUEimCHgEBBSMEGQEbHQEDDAYFCwMKAgImAgIhAQERAQUBHAYTh3oBAw8MoDGLZE+CeIQYChknDVmIdQEFDIEWiixpEoMcgRMDlCyBVYEcihiDMBYphBE X-IronPort-AV: E=Sophos;i="4.83,313,1352070000"; d="scan'208";a="182987735" Received: from mail-ie0-f182.google.com ([209.85.223.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 24 Nov 2012 19:35:25 +0100 Received: by mail-ie0-f182.google.com with SMTP id s9so14299661iec.27 for ; Sat, 24 Nov 2012 10:35:24 -0800 (PST) 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:content-transfer-encoding; bh=6suAkBzhPwBlSsGy/oLh/+tWrWsJnxThFwJ/0Syf1bU=; b=Bs75gKZ2TBKmbAHuGy1LfFCX+Y7kX7itAD+uZFO0JvQ4ZzEY+1e5S93Obmrm4X0mbI tUOhJY2pq+3h+e8FJ9t2yWpW0OwwCAyu+OpvMPWX10yKXJWD/uz18PaaVJrCYULFASWe xZJQAjfF3kRcWNuAFLp+B7q+Bf8njktv2kGsovMqTlTNnbBJPsMEf2aQMaAgWQO+Rixi Gn20fXxibdggt7ABX3a/PhTNqx9dEVWxjS/RYgIowQEUpo6pdDcll0y3j0ygc+/qCPB9 nO7MNPFTnDz0IgPEn/aIqHZNF0xvG5HWmCRSj6Pl3C403RNpuyDo3ch5MwVLeuCri7G/ BR4A== Received: by 10.50.180.133 with SMTP id do5mr9569749igc.2.1353782124523; Sat, 24 Nov 2012 10:35:24 -0800 (PST) MIME-Version: 1.0 Received: by 10.50.184.199 with HTTP; Sat, 24 Nov 2012 10:34:44 -0800 (PST) In-Reply-To: <20121124163405.GA2158@gmail.com> References: <20121123114328.GD31371@gmail.com> <20121124163405.GA2158@gmail.com> From: Gabriel Scherer Date: Sat, 24 Nov 2012 19:34:44 +0100 Message-ID: To: Chris Yocum Cc: =?ISO-8859-2?Q?Micha=B3_Kurcewicz?= , caml-list@inria.fr Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Monad Library? > [...] > type 'a t =3D Store of 'a > [...] > > This is a very, very basic implementation of a state monad? No it's not. What you implemented is the identity monad (type 'a t =3D 'a, only wrapped under a constructor) that doesn't emulate any effect at all. The state monad (over some fixed "state" type, for example "int" if your state is an integer) would use a definition of the form (untested code): module StateMonad : sig include MONAD type state val get : state t val set : state -> unit t val run : state -> 'a t -> state * 'a end =3D struct type state type 'a t =3D state -> state * 'a [...] end You should probably try to wrap your head around monads by reading documentation and implementing some of them yourself *before* looking for a third-party library that provide monadic facilities. Wojciech gave excellent references about monads. If you want something maybe more easy-going and still in OCaml, you could also have a look at Brian Hurt's "a Monad Tutorial for OCaml": http://blog.enfranchisedmind.com/2007/08/a-monad-tutorial-for-ocaml/ Of course, most of the literature on monads uses Haskell, the language in which they became popular first. It's actually quite easy to read Haskell code if you're already familiar with OCaml, so those documents should be accessible as well. Of course I don't recommend that if you're not already comfortable with OCaml semantics (... or Haskell's). On Sat, Nov 24, 2012 at 5:34 PM, Chris Yocum wrote: > Thanks everyone, > > So basically from what I understand this is kind of like a StateMonad. > It seems to me that the state monad (hiding state in the type system) > would be a large boon. > > So, for instance, > > module type MONAD =3D > sig > type 'a t > val return : 'a -> 'a t > val bind : 'a t -> ('a -> 'b t) -> 'b t > end > > module StateMonad : MONAD =3D > struct > type 'a t =3D Store of 'a > let return x =3D Store(x) > let bind s f =3D > match s with > | Store(x) -> f x > let access =3D function Store(x) -> x > end > > This is a very, very basic implementation of a state monad? > > Thanks again. > > Chris > > On Fri, Nov 23, 2012 at 09:59:30PM +0100, Micha=C5=82 Kurcewicz wrote: >> If Core is too complex for you then you may take a look at spotlib - a >> small and elegant library written by Jun Furuse: >> >> https://bitbucket.org/camlspotter/spotlib >> >> I use it together with pa_monad_custom for all my monad needs. >> >> Best, >> >> --mk >> >> On Fri, Nov 23, 2012 at 12:43 PM, Chris Yocum wrote: >> > Hi, >> > >> > I was looking into using Monads in my programs but I am slightly at a >> > loss as to what library is in general use. There is pa_monad but that >> > seems to be a ocamlp4 exention and not a library. There is >> > http://lambda.jimpryor.net/monad_library/ but that doesn't seem to be >> > in opam or in godi so I am unsure as to its status. >> > >> > Does anyone have any suggestion for a well supported monad library for >> > Ocaml? >> > >> > All the best, >> > Chris