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. Re: external sort (Keith Sheppard) 2. Re: external sort (Felipe Lessa) 3. Re: external sort (Chadda? Fouch?) 4. type class question from MReader #8 (MH) 5. Re: type class question from MReader #8 (Brandon S. Allbery KF8NH) 6. Re: type class question from MReader #8 (MH) 7. Recursive macros in hsc2hs (Maur??cio) 8. Re: Recursive macros in hsc2hs (Antoine Latter) 9. Re: Recursive macros in hsc2hs (Brandon S. Allbery KF8NH) ---------------------------------------------------------------------- Message: 1 Date: Sat, 11 Jul 2009 22:15:24 -0400 From: Keith Sheppard <keiths...@gmail.com> Subject: Re: [Haskell-beginners] external sort To: Felipe Lessa <felipe.le...@gmail.com> Cc: beginners@haskell.org Message-ID: <92e42b740907111915v6717d87biade02644f9072...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Felipe, Thanks. I need to learn how to use hoogle better :-) All, I've just figured out why I'm leaking file handles so please ignore question 1 -Keith On Sat, Jul 11, 2009 at 9:59 PM, Felipe Lessa<felipe.le...@gmail.com> wrote: > On Sat, Jul 11, 2009 at 08:40:10PM -0400, Keith Sheppard wrote: >> 2) I'm guessing there's a smarter way to do unwrapMonads? > > unwrapMonads is actually sequence :), see [1]. > > [1] > http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/Control-Monad.html#sequence > > -- > Felipe. > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -- keithsheppard.name ------------------------------ Message: 2 Date: Sat, 11 Jul 2009 23:27:45 -0300 From: Felipe Lessa <felipe.le...@gmail.com> Subject: Re: [Haskell-beginners] external sort To: beginners@haskell.org Message-ID: <20090712022745.gc23...@kira.casa> Content-Type: text/plain; charset=us-ascii On Sat, Jul 11, 2009 at 08:40:10PM -0400, Keith Sheppard wrote: > 4) Is there any other wacky stuff in my code that I should change? I would probably write readBinFiles as > readBinFiles :: [String] -> IO [BS.ByteString] > readBinFiles = mapM readB > where readB file = openBinaryFile file ReadMode >>= BS.hGetContents You may also write pointless code ;) > readBinFiles :: [String] -> IO [BS.ByteString] > readBinFiles = mapM_ $ flip (>>=) BS.hGetContents . flip openBinaryFile > ReadMode Another way of improving your code is trying to write the functions in the order that one would read them (that is, bottom-up or top-down). In the start you seem to be following a top-down approach until you reach a referecen to bufferPartialSortsBy which is on the other side :). HTH, -- Felipe. ------------------------------ Message: 3 Date: Sun, 12 Jul 2009 11:04:41 +0200 From: Chadda? Fouch? <chaddai.fou...@gmail.com> Subject: Re: [Haskell-beginners] external sort To: Felipe Lessa <felipe.le...@gmail.com> Cc: beginners@haskell.org Message-ID: <e9350eaf0907120204i68b84f33v8a16c78bb8...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Sun, Jul 12, 2009 at 4:27 AM, Felipe Lessa<felipe.le...@gmail.com> wrote: > On Sat, Jul 11, 2009 at 08:40:10PM -0400, Keith Sheppard wrote: >> 4) Is there any other wacky stuff in my code that I should change? > > I would probably write readBinFiles as > >> readBinFiles :: [String] -> IO [BS.ByteString] >> readBinFiles = mapM readB >>  where readB file = openBinaryFile file ReadMode >>= BS.hGetContents > > You may also write pointless code ;) > >> readBinFiles :: [String] -> IO [BS.ByteString] >> readBinFiles = mapM_ $ flip (>>=) BS.hGetContents . flip openBinaryFile >> ReadMode > You can greatly improve that by using the kleisli composition operator : > readBinFiles = mapM (BS.hGetContents <=< flip openBinaryFile ReadMode) But if this is lazy bytestrings, this will leak handles like crazy... A nice solution would be to use the safe-lazy-io package : it is easy to add a finalizer that will remove the file once hGetContents is finished (with System.IO.Lazy.Internal.finallyLI) and to read a list of files lazily without leaking handles (see System.IO.Lazy.concat). http://hackage.haskell.org/package/safe-lazy-io -- Jedaï ------------------------------ Message: 4 Date: Mon, 13 Jul 2009 23:43:40 -0400 From: MH <mha...@gmail.com> Subject: [Haskell-beginners] type class question from MReader #8 To: beginners@haskell.org Message-ID: <648da0750907132043q47269e42kccdfb6ef2c53f...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 I am reading the article from Monad Reader issue #8 called Type-Level Instant Insanity by Conrad Parker and I don't understand the part on recursive types. data Nil data Cons x xs data x ::: xs infixr 5 ::: class ListConcat a1 a2 a | a1 a2 -> a where listConcat :: a1 -> a2 -> a instance ListConcat Nil a a where listConcat = _|_ instance (ListConcat xs ys zs) => ListConcat (x ::: xs) ys (x ::: zs) where listConcat = _|_ 1. How does the last function becomes recursive? 2. Why do we need constraint '(ListConcat xs ys zs) =>' ? 3. I assume that listConcat function takes three arguments but from example provided, it takes two (see below): 4. Does the functional dependency sign (->) implies that the last argument is the return type? Main> :type listConcat (u:: R ::: G ::: B ::: Nil) (u:: W ::: Nil) listConcat (u::R:::G:::B:::Nil) (u::W:::Nil)::(:::) R ((:::) G ((:::) B ((:::) W Nil))) Thanks a lot. Malik ------------------------------ Message: 5 Date: Tue, 14 Jul 2009 01:12:39 -0400 From: "Brandon S. Allbery KF8NH" <allb...@ece.cmu.edu> Subject: Re: [Haskell-beginners] type class question from MReader #8 To: MH <mha...@gmail.com> Cc: beginners@haskell.org Message-ID: <d238cc63-8f84-4f8d-b27b-fa8c9ac86...@ece.cmu.edu> Content-Type: text/plain; charset="us-ascii" On Jul 13, 2009, at 23:43 , MH wrote: > class ListConcat a1 a2 a | a1 a2 -> a where > listConcat :: a1 -> a2 -> a > > instance ListConcat Nil a a where listConcat = _|_ > > instance (ListConcat xs ys zs) > => ListConcat (x ::: xs) ys (x ::: zs) where listConcat > = _|_ > > 1. How does the last function becomes recursive? > 2. Why do we need constraint '(ListConcat xs ys zs) =>' ? Your second question is the answer to the first. > 3. I assume that listConcat function takes three arguments but from > example provided, it takes two (see below): The last type in the (->) chain is the return type, not an argument. > 4. Does the functional dependency sign (->) implies that the last > argument is the return type? No, it says type a (which is designated as the return type by the definition of listConcat) is uniquely determined by the pair of argument types a1, a2 taken together. (That is, any given unique combination of argument types produces a unique result type.) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/beginners/attachments/20090714/9c80fff1/PGP-0001.bin ------------------------------ Message: 6 Date: Tue, 14 Jul 2009 10:05:03 -0400 From: MH <mha...@gmail.com> Subject: Re: [Haskell-beginners] type class question from MReader #8 To: "Brandon S. Allbery KF8NH" <allb...@ece.cmu.edu> Cc: beginners@haskell.org Message-ID: <648da0750907140705v64483313l118c36ccbccbf...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Could you please elaborate on how does the constraint (ListConcat xs ys zs) makes the instance ListConcat (x ::: xs) ys (x ::: zs) recursive. Also, I am interested to learn more about various ways to constrain type classes parameters, is there a paper you would recommend? Thanks On Tue, Jul 14, 2009 at 1:12 AM, Brandon S. Allbery KF8NH<allb...@ece.cmu.edu> wrote: > On Jul 13, 2009, at 23:43 , MH wrote: >> >> class ListConcat a1 a2 a | a1 a2 -> a where >> listConcat :: a1 -> a2 -> a >> >> instance ListConcat Nil a a where listConcat = _|_ >> >> instance (ListConcat xs ys zs) >> => ListConcat (x ::: xs) ys (x ::: zs) where listConcat = _|_ >> >> 1. How does the last function becomes recursive? >> 2. Why do we need constraint '(ListConcat xs ys zs) =>' ? > > Your second question is the answer to the first. > >> 3. I assume that listConcat function takes three arguments but from >> example provided, it takes two (see below): > > The last type in the (->) chain is the return type, not an argument. > >> 4. Does the functional dependency sign (->) implies that the last >> argument is the return type? > > No, it says type a (which is designated as the return type by the definition > of listConcat) is uniquely determined by the pair of argument types a1, a2 > taken together. (That is, any given unique combination of argument types > produces a unique result type.) > > -- > brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com > system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu > electrical and computer engineering, carnegie mellon university KF8NH > > > ------------------------------ Message: 7 Date: Tue, 14 Jul 2009 23:51:55 -0300 From: Maur??cio <briqueabra...@yahoo.com> Subject: [Haskell-beginners] Recursive macros in hsc2hs To: beginners@haskell.org Message-ID: <h3jg8c$fv...@ger.gmane.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed I'm trying to define a macro inside a template that generates an existing macro: --- #define hsc_test(hst,ct) \ { \ printf("#def inline int b_%s(void){return %s;}\n", hst,ct); \ printf("foreign import ccall b_%s :: CInt\n", hst); \ } --- Contrary to my expectation, the '#def' construct printed at the first 'printf' is included in the final haskell file, instead of beeing removed and replaced by a C function definition in a c header file. Is it possible to define an hsc_-like construct that generates code that is again parsed by hsc2hs? Thanks, Maurício ------------------------------ Message: 8 Date: Tue, 14 Jul 2009 22:28:19 -0500 From: Antoine Latter <aslat...@gmail.com> Subject: Re: [Haskell-beginners] Recursive macros in hsc2hs To: Maur??cio <briqueabra...@yahoo.com> Cc: beginners@haskell.org Message-ID: <694519c50907142028s53a14d47p4237b22d59a1b...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 On Tue, Jul 14, 2009 at 9:51 PM, Maurício<briqueabra...@yahoo.com> wrote: > I'm trying to define a macro inside a template that generates > an existing macro: > > --- > > #define hsc_test(hst,ct) \ > { \ > printf("#def inline int b_%s(void){return %s;}\n", hst,ct); \ > printf("foreign import ccall b_%s :: CInt\n", hst); \ > } > > --- > > Contrary to my expectation, the '#def' construct printed at the > first 'printf' is included in the final haskell file, instead of > beeing removed and replaced by a C function definition in a c > header file. > I thought CPP igored tokens occurring in strings? So CPP wouldn't even see the #define in the argument to printf. I'm not a C wizard, but I though that's how it worked. Antoine ------------------------------ Message: 9 Date: Wed, 15 Jul 2009 00:21:55 -0400 From: "Brandon S. Allbery KF8NH" <allb...@ece.cmu.edu> Subject: Re: [Haskell-beginners] Recursive macros in hsc2hs To: Maur??cio <briqueabra...@yahoo.com> Cc: beginners@haskell.org Message-ID: <345d5335-12b0-432f-9a5c-9c7b1e69d...@ece.cmu.edu> Content-Type: text/plain; charset="iso-8859-1" On Jul 14, 2009, at 22:51 , Maurí cio wrote: > I'm trying to define a macro inside a template that generates > an existing macro: Won't fly; cpp doesn't scan its own output recursively, so if you generate a #define in a macro it will appear in the output unexpanded. AFAIK cpphs is no different. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/beginners/attachments/20090715/6a8b43f7/PGP.bin ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 13, Issue 8 ****************************************