Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Pros and Cons of Haskell libsndfile packages? (Charles Turner) 2. Re: Pros and Cons of Haskell libsndfile packages? (Erik de Castro Lopo) 3. Re: Pros and Cons of Haskell libsndfile packages? (Charles Turner) 4. A Quantity Type - Integer without the Negative #'s (aditya siram) 5. Re: A Quantity Type - Integer without the Negative #'s (Daniel Fischer) 6. Re: A Quantity Type - Integer without the Negative #'s (Daniel Carrera) 7. Re: A Quantity Type - Integer without the Negative #'s (Magnus Therning) 8. Re: A Quantity Type - Integer without the Negative #'s (Alexander Dunlap) 9. SQL Lexer (Patrick LeBoutillier) 10. Re: A Quantity Type - Integer without the Negative #'s (Ashok Gautham) ---------------------------------------------------------------------- Message: 1 Date: Thu, 07 May 2009 19:06:37 -0400 From: Charles Turner <vze26...@optonline.net> Subject: [Haskell-beginners] Pros and Cons of Haskell libsndfile packages? To: beginners@haskell.org Message-ID: <5f197860-d089-4387-9c75-e95259b54...@optonline.net> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Hi all- I noticed that there were two different packages that provided a Haskell interface to the libsndfile library: HSoundFile: <http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HSoundFile > hsoundfile: <http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hsndfile > Does anyone have any comments of the relative merits of either of these? Thanks! Charles ------------------------------ Message: 2 Date: Fri, 8 May 2009 10:09:25 +1000 From: Erik de Castro Lopo <mle...@mega-nerd.com> Subject: Re: [Haskell-beginners] Pros and Cons of Haskell libsndfile packages? To: beginners@haskell.org Message-ID: <20090508100925.37745149.mle...@mega-nerd.com> Content-Type: text/plain; charset=US-ASCII Charles Turner wrote: > Hi all- > > I noticed that there were two different packages that provided a > Haskell interface to the libsndfile library: > > hsndfile: > <http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hsndfile That one is a indeed a haskell wrapper around libsndfile, while this one: > HSoundFile: > <http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HSoundFile is not, but rather, seems to be a pure Haskell Wave file decoder/encoder. It does not (yet) seem to handle other formats. > Does anyone have any comments of the relative merits of either of these? I'm probably biased, but I'm sure the former (hsndfile) opens more file formats and is more robust when parsing malformed files. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/ ------------------------------ Message: 3 Date: Fri, 08 May 2009 13:40:55 -0400 From: Charles Turner <vze26...@optonline.net> Subject: Re: [Haskell-beginners] Pros and Cons of Haskell libsndfile packages? To: beginners@haskell.org Message-ID: <38590b26-3068-4ecb-a4ef-1f1b847b8...@optonline.net> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes On May 7, 2009, at 8:09 PM, Erik de Castro Lopo wrote: > Charles Turner wrote: > That one is a indeed a haskell wrapper around libsndfile, while this > one: > >> HSoundFile: >> <http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HSoundFile >> Does anyone have any comments of the relative merits of either of >> these? > > I'm probably biased, but I'm sure the former (hsndfile) opens more > file > formats and is more robust when parsing malformed files. Hi Erik! In this case I think your bias is well-appreciated. Thanks so much for libsndfile, always one the first libraries I install on any new machine. Best, Charles ------------------------------ Message: 4 Date: Fri, 8 May 2009 13:22:23 -0500 From: aditya siram <aditya.si...@gmail.com> Subject: [Haskell-beginners] A Quantity Type - Integer without the Negative #'s To: beginners <beginners@haskell.org> Message-ID: <594f78210905081122l31cc683aof7c0661c6ff56...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Hi all, Is there a datatype in Haskell that can be used to represent only quantities >= 0? I got bitten by a bug because I forgot to reject an amount that was below zero after applying a decrementing operator. A simple unit test would have caught this, but I was wondering if there was some way of getting the type system to ensure this. thanks ... -deech -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090508/0a0a5703/attachment-0001.htm ------------------------------ Message: 5 Date: Fri, 8 May 2009 22:30:25 +0200 From: Daniel Fischer <daniel.is.fisc...@web.de> Subject: Re: [Haskell-beginners] A Quantity Type - Integer without the Negative #'s To: beginners@haskell.org Message-ID: <200905082230.25873.daniel.is.fisc...@web.de> Content-Type: text/plain; charset="iso-8859-15" Am Freitag 08 Mai 2009 20:22:23 schrieb aditya siram: > Hi all, > Is there a datatype in Haskell that can be used to represent only > quantities > > >= 0? I got bitten by a bug because I forgot to reject an amount that was > > below zero after applying a decrementing operator. A simple unit test would > have caught this, but I was wondering if there was some way of getting the > type system to ensure this. > > thanks ... > -deech I'm sure there are several implementations of a natural number datatype on Hackage (e.g. lazy Peano Numbers). And of course there are Word, Word32, Word64 (from Data.Word), but they wrap on underflow. Another option is to define an opaque type yourself: module Natural (Natural, mkNatural, maybeNatural) where newtype Natural = N Integer deriving (Eq, Ord, Show) mkNatural :: Integer -> Natural mkNatural n | n < 0 = error "Naturals must be non-negative" | otherwise = N n maybeNatural :: Integer -> Maybe Natural maybeNatural n | n < 0 = Nothing | otherwise = N n instance Num Natural where (N m) + (N n) = N (n+m) (N m) - (N n) = mkNatural (m-n) (N m) * (N n) = N (m*n) abs = id signum (N n) = if n == 0 then (N 0) else (N 1) negate n = error "Can't negate Naturals" fromInteger = mkNatural doesn't give you hard compile-time guarantees, but at least you get an error and not a hard-to-find bug. ------------------------------ Message: 6 Date: Fri, 08 May 2009 22:54:29 +0200 From: Daniel Carrera <daniel.carr...@theingots.org> Subject: Re: [Haskell-beginners] A Quantity Type - Integer without the Negative #'s To: beginners <beginners@haskell.org> Message-ID: <4a049c05.4080...@theingots.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed That's an interesting question. I would like to see the answer too. I can think of a completely impractical way to do it: data Quantity = 0 | 1 | 2 | 3 | ... | 65532 But of course, listing every integer seems like a dumb solution. But this gives me more confidence that there is a smart solution to your problem and we just need to find it. Daniel. aditya siram wrote: > Hi all, > Is there a datatype in Haskell that can be used to represent only > quantities >= 0? I got bitten by a bug because I forgot to reject an > amount that was below zero after applying a decrementing operator. A > simple unit test would have caught this, but I was wondering if there > was some way of getting the type system to ensure this. > > thanks ... > -deech > > > ------------------------------------------------------------------------ > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners ------------------------------ Message: 7 Date: Fri, 08 May 2009 23:06:37 +0100 From: Magnus Therning <mag...@therning.org> Subject: Re: [Haskell-beginners] A Quantity Type - Integer without the Negative #'s To: beginners@haskell.org Message-ID: <4a04aced.5060...@therning.org> Content-Type: text/plain; charset="utf-8" aditya siram wrote: > Hi all, > Is there a datatype in Haskell that can be used to represent only > quantities >= 0? I got bitten by a bug because I forgot to reject an > amount that was below zero after applying a decrementing operator. A > simple unit test would have caught this, but I was wondering if there > was some way of getting the type system to ensure this. Maybe Word32 (or one of it's siblings) would do? It's basically the same as 'unsigned int' in C, so it can under- and over-flow. /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnusï¼ therningï¼org Jabber: magnusï¼ therningï¼org http://therning.org/magnus identi.ca|twitter: magthe -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/beginners/attachments/20090508/c11af4db/signature-0001.bin ------------------------------ Message: 8 Date: Fri, 8 May 2009 15:36:55 -0700 From: Alexander Dunlap <alexander.dun...@gmail.com> Subject: Re: [Haskell-beginners] A Quantity Type - Integer without the Negative #'s To: aditya siram <aditya.si...@gmail.com> Cc: beginners <beginners@haskell.org> Message-ID: <57526e770905081536x73e564a8i9edbfaecf9a38...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Fri, May 8, 2009 at 11:22 AM, aditya siram <aditya.si...@gmail.com> wrote: > Hi all, > Is there a datatype in Haskell that can be used to represent only quantities >>= 0? I got bitten by a bug because I forgot to reject an amount that was > below zero after applying a decrementing operator. A simple unit test would > have caught this, but I was wondering if there was some way of getting the > type system to ensure this. > > thanks ... > -deech There are a number of ways of doing this, none of them entirely satisfactory. The essential problem is that subtraction becomes a partial function; i.e. if you try to subtract a and b, there's no way for the compiler to statically know if that's going to be nonnegative or not. One option would be to make a newtype of Integer, define (+), (*), etc. as with regular integers, define abs = id, negate = undefined. Then you can either make (-) a partial function (as in (NonNeg x) - (NonNeg y) = case x - y of z | z >= 0 -> z | otherwise -> undefined ) or leave subtraction undefined and make a maybeSubtract function that returns a Maybe value based on whether or not the result would be positive or negative. A third option would be to just take the absolute value of the result of a subtraction, although this should be used ONLY in situations where it is appropriate because usually you want to distinguish between x and -x. You could also use Peano numerals, but I don't think that those are very efficient. That's where you define data Nat = Zero | Succ Nat and so 3 :: Nat = Succ (Succ (Succ Zero)) etc. Hope that's of some help to you. Alex ------------------------------ Message: 9 Date: Fri, 8 May 2009 21:53:04 -0400 From: Patrick LeBoutillier <patrick.leboutill...@gmail.com> Subject: [Haskell-beginners] SQL Lexer To: beginners <beginners@haskell.org> Message-ID: <b217a64f0905081853h2557d4adl4c775aa8c6ae7...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Hi all, In the process of writing an SQL parser I started by writing a lexer. The code can be found here: http://hpaste.org/fastcgi/hpaste.fcgi/view?id=4736#a4736 You can run it like this in ghci: Prelude SQL.Lexer> runLexer "select * from TABLE order by FIELD" [Token Reserved "select",Token Space " ",Token Operator "*",Token Space " ",Token Reserved "from",Token Space " ",Token Identifier "TABLE",Token Space " ",Token Reserved "order",Token Space " ",Token Reserved "by",Token Space " ",Token Identifier "FIELD"] Since this is pretty much my first Haskell project over 10 lines long, I'm looking for some feedback of any kind. Ultimately I would like to use this lexer to build a functional SQL parser using Parsec. Thanks, Patrick -- ===================== Patrick LeBoutillier Rosemère, Québec, Canada ------------------------------ Message: 10 Date: Sat, 9 May 2009 09:32:29 +0530 From: Ashok Gautham <scriptdevil.hask...@gmail.com> Subject: Re: [Haskell-beginners] A Quantity Type - Integer without the Negative #'s To: beginners <beginners@haskell.org> Message-ID: <d6c99d440905082102h3599a40bp2526c61c9d8a7...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 On Sat, May 9, 2009 at 2:24 AM, Daniel Carrera <daniel.carr...@theingots.org> wrote: > That's an interesting question. I would like to see the answer too. I can > think of a completely impractical way to do it: > > data Quantity = 0 | 1 | 2 | 3 | ... | 65532 > > > But of course, listing every integer seems like a dumb solution. But this > gives me more confidence that there is a smart solution to your problem and > we just need to find it. > > Daniel. What about operators? --- Ashok `ScriptDevil` Gautham ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 11, Issue 8 ****************************************