From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: *** X-Spam-Status: No, score=3.8 required=5.0 tests=DNS_FROM_RFC_POST,HTML_10_20, HTML_MESSAGE,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 99DA1BC37 for ; Wed, 13 May 2009 19:24:35 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AggDAA+fCkrRVcbmkGdsb2JhbACCITKUBT8BAQEBBwsMBxEDpwSBEpAeAQMBA4N/BQ X-IronPort-AV: E=Sophos;i="4.41,188,1241388000"; d="scan'208";a="26113924" Received: from rv-out-0506.google.com ([209.85.198.230]) by mail2-smtp-roc.national.inria.fr with ESMTP; 13 May 2009 19:24:34 +0200 Received: by rv-out-0506.google.com with SMTP id k40so488723rvb.3 for ; Wed, 13 May 2009 10:24:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=rdPT4vwXxBslQA813lU2hVbFTsakKHjc/OAsdTnCf/A=; b=qJMHT2VF9uXGxo3CxZuGKpdlZ+cAAF5gFLt6ptCGve23xWgAyJJKaEBkQekPfNmHIL UEa+zUjVIFDtTILHIV6TyoO7dwowY2iU4Ec8YFYtzN/CjGsJ4jC2KRZ2EAd1xa7881MK 2P4UIAo9dJfDKPwqqmC8oU6BfRdIbw7kDkjvk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=dTN5H6pvMnDe5gGgsXwn8e0q/iqrhgxQByqtNbcGeZT3Q11He7LmFomvYjVVHbox+1 0m9YOFXCVBi9lwFdOKmNUicZl5QwRl6ED1IjRxq34oxDzLscbg1lbqagwnF3CtoEmyFg t7yaBbDRobaKDAWTmpdZUbzWlLowGG8OP/1FA= MIME-Version: 1.0 Received: by 10.142.49.20 with SMTP id w20mr398054wfw.278.1242235473442; Wed, 13 May 2009 10:24:33 -0700 (PDT) Date: Wed, 13 May 2009 10:24:33 -0700 Message-ID: <9da743ed0905131024u53a207f0s9e963be782f3f2c6@mail.gmail.com> Subject: Newbie list question From: Joel Christner To: caml-list@yquem.inria.fr, Joel Christner Content-Type: multipart/alternative; boundary=000e0cd2a0a81f388b0469ce7cd3 X-Spam: no; 0.00; rec:01 rec:01 strings:01 strings:01 data:02 data:02 expression:02 expression:02 newbie:02 newbie:02 match:02 match:02 failing:02 failing:02 string:02 --000e0cd2a0a81f388b0469ce7cd3 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hello, I posted this question on a couple of newsgroups as well, please pardon the cross-posting and the newbie question. What I'm wanting to do is create a ref list that contains a series of strings, i.e. # let varlist = ref [];; # let a = "a";; # let b = "b";; # let c = "c";; Then throughout the course of program operation, I will be adding data into this list, i.e.: # varlist.contents <- a::varlist.contents;; # varlist.contents <- b::varlist.contents;; # varlist.contents <- c::varlist.contents;; Which is working fine, i.e. # varlist.contents;; - : string list = ["c"; "b"; "a"] But what I'm trying to do next I can't figure out how to get working. What I'd like to do is have a function that first checks to see if the item is already in the ref list. If it is, do nothing. If it isn't, add it. Here's what I tried, which is of course failing. If anyone has a suggestion on how to make it work would you please help me out? # let rec addvariable stringdata listname = match listname.contents with | [] -> (listname.contents <- stringdata::listname.contents); () | [a] -> if a.contents = stringdata then () else (listname.contents <- stringdata::listname.contents); () | h::t -> if h.contents = stringdata then () else addvariable stringdata t.contents ;; Which returns... This expression has type 'a ref but is here used with type 'a # Does anyone have any suggestions on how to change the above to make it work? Basically I want the function to either 1) add the contents to the list if no duplicates exist and return unit or 2) return unit if it determines that the string is already there. Thanks for any and all help Joel --000e0cd2a0a81f388b0469ce7cd3 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hello,

I posted this question on a couple of newsgroups as well, ple= ase pardon the cross-posting and the newbie question.

What I'm w= anting to do is create a ref list that contains a series of
strings, i.e= .
# let varlist =3D ref [];;
# let a =3D "a";;
# let b =3D &q= uot;b";;
# let c =3D "c";;

Then throughout the cou= rse of program operation, I will be adding data
into this list, i.e.:# varlist.contents <- a::varlist.contents;;
# varlist.contents <- b::varlist.contents;;
# varlist.contents <- = c::varlist.contents;;

Which is working fine, i.e.
# varlist.conte= nts;;
- : string list =3D ["c"; "b"; "a"]<= br>
But what I'm trying to do next I can't figure out how to get wo= rking.
What I'd like to do is have a function that first checks to s= ee if the
item is already in the ref list.=A0 If it is, do nothing.=A0 I= f it isn't,
add it.=A0 Here's what I tried, which is of course failing.=A0 If anyon= e has
a suggestion on how to make it work would you please help me out?<= br>
# let rec addvariable stringdata listname =3D
=A0 match listname.= contents with
=A0 | [] -> (listname.contents <- stringdata::listname.contents); ()<= br>=A0 | [a] -> if a.contents =3D stringdata then () else (listname.cont= ents <-
stringdata::listname.contents); ()
=A0 | h::t -> if h.c= ontents =3D stringdata then () else addvariable
stringdata t.contents
;;

Which returns...
This expression has = type 'a ref but is here used with type 'a
#

Does anyone h= ave any suggestions on how to change the above to make it
work?=A0 Basic= ally I want the function to either 1) add the contents to
the list if no duplicates exist and return unit or 2) return unit if it
= determines that the string is already there.

Thanks for any and all = help
Joel
--000e0cd2a0a81f388b0469ce7cd3--