From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 A09D0BBAF for ; Thu, 15 Jul 2010 21:56:23 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkwCAHIEP0xKfVM0kGdsb2JhbACDHpxGCBUBAQEBCQkMBxEDH614O4IPhXEuiFMBAQMFhC1yBIN+hFI X-IronPort-AV: E=Sophos;i="4.55,210,1278280800"; d="ml'?scan'208";a="63865182" Received: from mail-gw0-f52.google.com ([74.125.83.52]) by mail1-smtp-roc.national.inria.fr with ESMTP; 15 Jul 2010 21:56:23 +0200 Received: by gwj17 with SMTP id 17so926271gwj.39 for ; Thu, 15 Jul 2010 12:56:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=TUI7ghKMIhCZ9TaGWDAC0xzWJ5jS/0xP4c5cPL+5y+o=; b=tkCby2sXJ8zF5sRe2w853FosJBHAIv6AzVk30Zsq5VKhVT141SLukTnKAlgw0AJqi+ kEutHWd2f0HgEA8XJwdgWZm6snd+zTc35ZjmKjh+dt4c/Ct/iMbPwFoJryD5DSL4BGks 9hhhwRO5QQQkOsuunkQwVEP8lZR88unZ0xvzE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=V0aIpogxMFAzYSsNfvYVfzKZPdsK4mtl+VnYDIFAe5kL9PhInsCI/xkGVpvIpsJqlh NzCjv0vF94L1rtIkfayuT4D9HdgwKWA5uOXnoEG9x06nrKNnwrI+TkfW1pycUETkopey HHdO+O03ZWUwQ052u1SxOO/CohChFvATsCfgE= MIME-Version: 1.0 Received: by 10.101.158.19 with SMTP id k19mr142730ano.220.1279223781833; Thu, 15 Jul 2010 12:56:21 -0700 (PDT) Received: by 10.100.212.6 with HTTP; Thu, 15 Jul 2010 12:56:21 -0700 (PDT) In-Reply-To: <87zkxsfvsg.fsf@frosties.localdomain> References: <87sk3mcaeq.fsf@frosties.localdomain> <87zkxsfvsg.fsf@frosties.localdomain> Date: Thu, 15 Jul 2010 14:56:21 -0500 Message-ID: Subject: Re: [Caml-list] Smart ways to implement worker threads From: Rich Neswold To: Goswin von Brederlow Cc: caml-list@yquem.inria.fr Content-Type: multipart/mixed; boundary=0016e64d9a151abcb7048b727ffd X-Spam: no; 0.00; ocaml:01 ocaml:01 ocaml's:01 syntax:01 ocaml's:01 syntax:01 threads:01 wrote:01 wrote:01 caml-list:01 differs:01 differs:01 short:01 short:01 translate:04 X-Attachments: cset="UTF-8" cset="UTF-8" type="text/x-ocaml" name="mergesort.ml" name="mergesort.ml" --0016e64d9a151abcb7048b727ffd Content-Type: multipart/alternative; boundary=0016e64d9a151abcac048b727ffb --0016e64d9a151abcac048b727ffb Content-Type: text/plain; charset=UTF-8 On Thu, Jul 15, 2010 at 1:24 PM, Goswin von Brederlow wrote: > It is too bad I don't want to learn CML but use Ocaml. The CML examples > from the book don't translate into ocaml since the interface is just a > little bit different and those differences are what throws me off. > > So could you give a short example? E.g. the merge sort from the book. > You're right: OCaml's syntax differs enough from the text that it's annoying to cut-n-paste the examples. Fortunately most example are a few lines of code, so I didn't realize how difficult it could be on a larger example (like the merge sort example.) Attached is my translation of the mergeSort from the book. You get to play with it and see if it works :) -- Rich Google Reader: https://www.google.com/reader/shared/rich.neswold Jabber ID: rich@neswold.homeunix.net --0016e64d9a151abcac048b727ffb Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Thu, Jul 15, 2010 at 1:24 PM, Goswin von Brederlow <= ;goswin-v-b@web.de> wrot= e:
It is too bad I don't want to learn CML but use Ocaml= . The CML examples
from the book don't translate into ocaml since the interface is just a<= br> little bit different and those differences are what throws me off.
=C2=A0
So could you give = a short example?=C2=A0E.g. the merge sort from the book.

You're right: OCaml's syntax d= iffers enough from the text that it's annoying to cut-n-paste the examp= les. Fortunately most example are a few lines of code, so I didn't real= ize how difficult it could be on a larger example (like the merge sort exam= ple.)

Attached is my translation of the mergeSort from the book. Y= ou get to play with it and see if it works =C2=A0:)
--0016e64d9a151abcac048b727ffb-- --0016e64d9a151abcb7048b727ffd Content-Type: text/x-ocaml; charset=US-ASCII; name="mergesort.ml" Content-Disposition: attachment; filename="mergesort.ml" Content-Transfer-Encoding: base64 X-Attachment-Id: f_gbo0pbef0 b3BlbiBFdmVudAoKbGV0IG15U2VuZCBjIGQgPSBzeW5jIChzZW5kIGMgZCkKYW5kIG15UmVjdiBj ID0gc3luYyAocmVjZWl2ZSBjKQoKbGV0IHNwYXduIGYgPQogIGlnbm9yZSAoVGhyZWFkLmNyZWF0 ZSBmICgpKQoKbGV0IHNwbGl0IChpbkNoLCBvdXRDaDEsIG91dENoMikgPQogIGxldCByZWMgbG9v cCA9IGZ1bmN0aW9uCiAgICB8IChOb25lLCBfLCBfKSAtPiAobXlTZW5kIG91dENoMSBOb25lOyBt eVNlbmQgb3V0Q2gyIE5vbmUpCiAgICB8ICh4LCBvdXQxLCBvdXQyKSAtPiAobXlTZW5kIG91dDEg eDsgbG9vcCAobXlSZWN2IGluQ2gsIG91dDIsIG91dDEpKQogIGluCiAgICBsb29wIChteVJlY3Yg aW5DaCwgb3V0Q2gxLCBvdXRDaDIpCgpsZXQgbWVyZ2UgKGluQ2gxLCBpbkNoMiwgKG91dENoIDog aW50IG9wdGlvbiBjaGFubmVsKSkgPQogIGxldCByZWMgY29weSAoZnJvbUNoLCB0b0NoKSA9CiAg ICBsZXQgcmVjIGxvb3AgdiA9CiAgICAgIGJlZ2luCglteVNlbmQgdG9DaCB2OwoJbWF0Y2ggdiB3 aXRoCgkgIHwgU29tZSBfIC0+IGxvb3AgKG15UmVjdiBmcm9tQ2gpCgkgIHwgTm9uZSAtPiAoK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