From cgibbard at gmail.com Fri Feb 1 00:09:28 2008 From: cgibbard at gmail.com (Cale Gibbard) Date: Fri Feb 1 00:08:57 2008 Subject: [Haskell-cafe] A handy little consequence of the Cont monad Message-ID: <89ca3d1f0801312109k718f60a9maeef1c5e1025cc28@mail.gmail.com> Hello, Today on #haskell, resiak was asking about a clean way to write the function which allocates an array of CStrings using withCString and withArray0 to produce a new with* style function. I came up with the following: nest :: [(r -> a) -> a] -> ([r] -> a) -> a nest xs = runCont (sequence (map Cont xs)) withCStringArray0 :: [String] -> (Ptr CString -> IO a) -> IO a withCStringArray0 strings act = nest (map withCString strings) (\rs -> withArray0 nullPtr rs act) Originally, I'd written nest without using the Cont monad, which was a bit of a mess by comparison, then noticed that its type was quite suggestive. Clearly, it would be more generally useful whenever you have a bunch of with-style functions for managing the allocation of resources, and would like to turn them into a single with-style function providing a list of the acquired resources. - Cale From lemming at henning-thielemann.de Fri Feb 1 05:12:28 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Feb 1 05:11:43 2008 Subject: [Haskell-cafe] A handy little consequence of the Cont monad In-Reply-To: <89ca3d1f0801312109k718f60a9maeef1c5e1025cc28@mail.gmail.com> References: <89ca3d1f0801312109k718f60a9maeef1c5e1025cc28@mail.gmail.com> Message-ID: On Fri, 1 Feb 2008, Cale Gibbard wrote: > Hello, > > Today on #haskell, resiak was asking about a clean way to write the > function which allocates an array of CStrings using withCString and > withArray0 to produce a new with* style function. I came up with the > following: > > nest :: [(r -> a) -> a] -> ([r] -> a) -> a > nest xs = runCont (sequence (map Cont xs)) > > withCStringArray0 :: [String] -> (Ptr CString -> IO a) -> IO a > withCStringArray0 strings act = nest (map withCString strings) > (\rs -> withArray0 nullPtr rs act) > > Originally, I'd written nest without using the Cont monad, which was a > bit of a mess by comparison, then noticed that its type was quite > suggestive. > > Clearly, it would be more generally useful whenever you have a bunch > of with-style functions for managing the allocation of resources, and > would like to turn them into a single with-style function providing a > list of the acquired resources. Nice idea. Could serve as an explanation what the Cont monad is good for. What about uploading it to the Wiki Category:Idioms ? From Christian.Maeder at dfki.de Fri Feb 1 05:32:35 2008 From: Christian.Maeder at dfki.de (Christian Maeder) Date: Fri Feb 1 05:31:55 2008 Subject: [Haskell-cafe] Re: derive Pretty? In-Reply-To: <1f3dc80d0801311500t4107afabwafe370deb084870b@mail.gmail.com> References: <1f3dc80d0801311500t4107afabwafe370deb084870b@mail.gmail.com> Message-ID: <47A2F543.7040005@dfki.de> Greg Fitzgerald wrote: > Is it possible to automatically derive instances of Pretty > ? > If no, what do most do when it comes to pretty-printing large data types? We do it manually. Usually you have to decide anyway which bits to omit or add (only implicitly indicated by a data constructor) and if you compose things vertically or beside (or nested or whatever) to make it look pretty. HTH Christian see i.e an abstract syntax at: http://www.dfki.de/sks/hets/src-distribution/daily/Hets/docs/CASL-AS_Basic_CASL.html the pretty printer code is here http://www.dfki.de/sks/hets/src-distribution/daily/Hets/CASL/ToDoc.hs our pretty printer wrapper (for text and latex tailored for Hets) http://www.dfki.de/sks/hets/src-distribution/daily/Hets/docs/Common-Doc.html (try "versions" instead of "daily", if a "daily" went wrong) From dekudekuplex at yahoo.com Fri Feb 1 05:51:35 2008 From: dekudekuplex at yahoo.com (Benjamin L. Russell) Date: Fri Feb 1 05:50:50 2008 Subject: [Haskell-cafe] anybody can tell me the pronuncation of "haskell"? In-Reply-To: Message-ID: <49382.7214.qm@web30204.mail.mud.yahoo.com> Here in Japan, it's pronounced in four syllables with no accent, as follows: Hah (as in "Hah, I see.") Sue (as in the name) Ke (as in the first syllable of "ketchup") Ru (as in the first syllable of "Lucas," since there is no difference between "l" and "r" sounds in Japanese) Put together, it sounds as follows: Hah-Sue-Ke-Ru Here's the URL of the Japanese Wikipedia page for Haskell Curry (for those who can read Japanese): http://ja.wikipedia.org/wiki/%E3%83%8F%E3%82%B9%E3%82%B1%E3%83%AB%E3%83%BB%E3%82%AB%E3%83%AA%E3%83%BC Benjamin L. Russell --- Paulo Tanimoto wrote: > On Jan 29, 2008 11:19 AM, Jeremy Apthorp > wrote: > > Another Japanese word adopted from Portuguese is > their word for "bread": "pan". > > "tabako" too, I believe (it's not even written in > katakana). > > Now, how do the Japanese pronounce Haskell, I'd like > to know. > > Paulo > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From dan.doel at gmail.com Fri Feb 1 05:55:25 2008 From: dan.doel at gmail.com (Dan Doel) Date: Fri Feb 1 05:53:24 2008 Subject: [Haskell-cafe] Announce: CC-delcont 0.2 Message-ID: <200802010555.25810.dan.doel@gmail.com> Hello all, After much distraction and laziness on my part (my apologies), I have finally gotten around to putting together a new release of the delimited continuations library CC-delcont. It is now available on hackage. Relevant changes include: * Now builds in GHC-6.8.x * Builds with -Wall (and the code was cleaned up to make as little noise as possible) (Thanks to gwern for the above) Also included is a new module, Control.Monad.CC.Cursor, which provides some functions for reifying traversals into cursors that can be passed around and manipulated. It's still in its infancy, but I hope to eventually include generalized zippers and such. GHC 6.8 or greater is required to build, and haddock 2.0 or greater is required to generate the documentation. Links: * hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/CC-delcont-0.2 * darcs: http://code.haskell.org/~dolio/CC-delcont/ * a brief tutorial: http://haskell.org/haskellwiki/Library/CC-delcont (I've not had too much feedback on this, so if anyone has trouble following some sections, or has ideas on how to better explain delimited continuations, changes are welcome.) Once again, if you discover any bugs, or have any suggestions, don't hesitate to let me know. -- Dan Doel From apfelmus at quantentunnel.de Fri Feb 1 06:13:04 2008 From: apfelmus at quantentunnel.de (apfelmus@quantentunnel.de) Date: Fri Feb 1 06:12:30 2008 Subject: [Haskell-cafe] Data.Ord and Heaps (Was: Why functional programming matters) Message-ID: <288B9431-ADC3-46D3-97F4-6A219388E015@quantentunnel.de> Stephan Friedrichs wrote: > apfelmus wrote: >> [...] >> Feedback: I think the HeapPolicy thing is too non-standard. The =20 >> canonical way would be to use a MinHeap and let the Ord instance =20 >> handle everything. A MaxHeap can then be obtained via a different =20 >> Ord instance >> newtype Ord a =3D> Reverse a =3D Reverse { unReverse :: a } >> instance Ord a =3D> Ord (Reverse a) where >> compare =3D comparing unReverse >> This newtype should be in Data.Ord, of course. Being > > This solution should be used for all collections depending on Ord =20 > instances, including Data.Map, Data.Set and others. As long as I =20 > only include it in my tiny heap package, it is as 'non-standard' as =20= > my approach, isn't it? Yes. I mean "non-standard" in the software-reuse sense, i.e. Ord is =20 for user-defined orderings and should be the only such mechanism in =20 order to enable reuse. In fact, Data.Heap clearly shows that Data.Ord =20= is currently missing functionality. >> Simply setting >> type MaxHeap a =3D MinHeap (Reverse a) >> is inferior to a "native" MaxHeap since we'd have to pack/unpack =20 >> the Reverse all the time. But a type class for heaps - which =20 >> should be present anyway - can solve that problem: >> class Heap h where >> [...] >> instance Heap MinHeap where ... >> newtype MaxHeap a =3D M (MinHeap (Reverse a)) >> instance Heap MaxHeap where ... > > I've actually thought about this. Realising MinHeap and MaxHeap is =20 > no problem, but I decided against it, because implementing a custom =20= > order becomes quite complicated: You have to declare an > > newtype MyHeap a =3D ... > > instance Heap MyHeap where > -- about 10 functions > > instead of just > > data PriorityPolicy > > instance HeapPolicy PP MyPriorityType where > heapCompare =3D const (comparing priority) Note that the Heap class contains only three primitive operations =20 (empty, insert, viewHead), all the others have default =20 implementations in terms of those three. There is even an =20 underappreciated unfold among them :) toAscList =3D unfoldr viewHead The structure becomes especially clear by noting that any Heap is =20 defined by just two primitives inject :: Ord a =3D> Maybe (a, Heap a) -> Heap a view :: Ord a =3D> Heap a -> Maybe (a, Heap a) We have inject =3D maybe empty (uncurry insert) . This is just like =20= lists, except that view . inject =AD id since view returns the =20 smallest element. However, just that we managed to reduce the number of primitive =20 operations doesn't mean that the policy approach isn't preferable. It =20= needs 0 primitive operations, after all. But as foreshadowed in my =20 reply, it's possible to do policies within Ord. Don't stop thinking =20 about your good idea just because you can start coding :) Here's one way to do it: module Data.Ord where ... class (Ord p a) =3D> OrdPolicy p a where -- the policy p is a =20= type constructor to :: a -> p a from :: p a -> a instance OrdPolicy Identity a where ... newtype Reverse a =3D Reverse a instance Ord a =3D> Reverse a where compare =3D flip $ comparing from instance OrdPolicy Reverse a where to =3D Reverse; from (Reverse x) =3D x module Data.Heap where ... newtype Heap p a =3D Heap (MinHeap (p a)) type MaxHeap a =3D Heap Reverse a class Ord a =3D> Heap h a | h -> a where empty :: h insert :: a -> h -> h viewHead :: h -> Maybe (a, h) instance OrdPolicy p a =3D> Heap (Heap p a) a where ... What I don't like about this is that the policy is not polymorphic in =20= the element types, forcing the Heap class to be multi-parameter. I'd =20 really like to write class (forall a . Ord p a) =3D> OrdPolicy p where but I guess that's (currently) not possible. The original "phantom =20 policy" approach can't quite do this either: module Data.Ord where ... newtype OrdBy p a =3D OrdBy { unOrdBy :: a } data Reverse instance Ord a =3D> Ord (OrdBy Reverse a) where compare =3D flip $ comparing unOrdBy module Data.Heap where ... newtype Heap p a =3D Heap (MinHeap (OrdBy p a)) type MaxHeap a =3D Heap Reverse a class Heap h where empty :: Ord a =3D> h a insert :: Ord a =3D> a -> h a -> h a viewHead :: Ord a =3D> h a -> Maybe (a, h a) instance (Ord (OrdBy p a)) =3D> Heap (Heap p) where -- forall a? ... However, a distinct advantage of using OrdBy for all ordering =20 policies is that the from and to functions are no longer =20 necessary. All ordering policies use the same type OrdBy which =20 automatically guarantees that from and to are inverse to each =20 other. This would be an informal requirement otherwise, so I think =20 that phantom policies are clearly superior to type constructor =20 policies. Fortunately, this is orthogonal to making Heap a multi-=20 parameter type class and ensuring that OrdBy p a instances are =20 polymorphic in a . >> In conclusion: the ordering policy stuff should not be part of =20 >> Data.Heap, this is a job for Data.Ord. > As mentioned above: This sounds really useful. How about you =20 > propose this to the base-package maintainers? :) What, me? :D Regards, apfelmus From Malcolm.Wallace at cs.york.ac.uk Fri Feb 1 06:25:53 2008 From: Malcolm.Wallace at cs.york.ac.uk (Malcolm Wallace) Date: Fri Feb 1 06:27:26 2008 Subject: [Haskell-cafe] Re: hxt memory useage In-Reply-To: References: <200801241449.26827.matthew.pocock@ncl.ac.uk> <4798D33B.5010500@vex.net> <200801241917.33281.matthew.pocock@ncl.ac.uk> Message-ID: <20080201112553.7040b7d4.Malcolm.Wallace@cs.york.ac.uk> "Rene de Visser" wrote: > Even if you replace parsec, HXT is itself not > incremental. (It stores the whole XML document in memory as a tree, > and the tree is not memory effecient. If the usage pattern of the tree is search-and-discard, then only enough of the tree to satisfy the search needs to be stored in memory at once. Everything from the root to the first node of interest can easily be pruned by the garbage collector. A paper describing the lazy parsing technique, and using XML-parsing as its motivating example, is available at http://www.cs.york.ac.uk/~malcolm/partialparse.html > >> haxml offers the choice of non-incremental parsers and incremental > >> parsers. Indeed. This lazy incremental parser for XML is available in the development version of HaXml: http://www.cs.york.ac.uk/fp/HaXml-devel The source code for partial parsing is available in a separate package: http://www.cs.york.ac.uk/fp/polyparse These lazy parser combinators are roughly between 2x - 5x faster than Parsec on large inputs (although the strict variation is about 2x slower than Parsec). Regards, Malcolm From magnus at therning.org Fri Feb 1 06:42:14 2008 From: magnus at therning.org (Magnus Therning) Date: Fri Feb 1 06:41:40 2008 Subject: [Haskell-cafe] Cabal, GHC, FFI and Visual Studio on Windows Message-ID: <47A30596.6080209@therning.org> Is it possible to get Cabal to use 'cl' (Microsoft's C/C++ compiler shipped with Visual Studio Express)? I've found the Wiki page on using Visual Studio to create a DLL, then convert it to a .a file so that GHC can consume it. I'd rather skip using Visual Studio to build things and just ship a Cabalised package. /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?gmail?com http://therning.org/magnus What if I don't want to obey the laws? Do they throw me in jail with the other bad monads? -- Daveman -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080201/8f5412be/signature.bin From dekudekuplex at yahoo.com Fri Feb 1 06:45:08 2008 From: dekudekuplex at yahoo.com (Benjamin L. Russell) Date: Fri Feb 1 06:44:24 2008 Subject: [Haskell-cafe] Re: anybody can tell me the pronuncation of?"haskell"? In-Reply-To: Message-ID: <593130.51738.qm@web30208.mail.mud.yahoo.com> According to the "Gogen Yurai Jiten" (Etymology Derivation Dictionary") (http://gogen-allguide.com/a/arigatou.html), the etymology of "arigato" ("arigatou" when entered into a Japanese input method editor, such as Kotoeri) is as follows (at the risk of moji-bake (garbled text), I have included the Japanese text in Japanese characters before each translated portion): - translated text follows immediately after this line - ???????????????????A?`?e???u?L???????i???????????j?v???A?p?`?u?L???????i???????????j?v???E?????????A???????????????????B The etymology of "arigatou" is that the te-form [loosely translated as "conjunctive form"] "arigataku" of the adjective "arigatashi" changed in form to end in the "u" sound, and became "arigatou." ?u?L???????i???????????j?v???A?u?L???i?????j?????v???u?????i???????j?v?????????????A?{?????u???????????v???u?????????M?d???v?????????????\?????B "Arigatashi" has the meaning of "being" being "rare"/"difficult," and originally expressed the meaning of "rare" or "uncommon and precious." ?w?????q?x???u???????????????v?????A?u???????????????????????v???????????A???????A?u?????????????v?????????????????p?????????????B In [the scene] "Arigataki Mono" ["That Which is Uncommon/Precious] ] of "Makura no Soushi" [The Pillow Book] [see http://en.wikipedia.org/wiki/The_Pillow_Book], it is also used to mean "it is difficult to be in this world"; i.e., "difficult to spend [time in]." ???????????A?????????????M?d?????????????????????????????????????????????A?@???I?????????C?????????????????????A???????~?A?????????????????????????L???????B When medieval times arrived, from [the idea of] charity of the Buddha, etc., in obtaining that which is precious and difficult to obtain, it came to express a feeling of gratitude, and in recent times and later, it spread to general use as the meaning of gratitude. ?|???g?K???????u?I?u???K?[?h?iobrigado?j?v?????A?u???????????v?????????????????????????????????????A?|???g?K???l???K???????O?????g?????????????t???|???g?K???????R?????????????????A?u?I?u???K?[?h?v???u???????????v???????????????????????b???A???x?????????????????B There is a myth that from "obrigado" of Portuguese, people came to say "arigatou," but it cannot be the case that a word used before Portuguese people [first] visited Japan was derived from the Portuguese language; it just so happens to be the case that the sounds of "obrigado" and "arigatou" are similar, and this is a vulgar myth. - translated text ends immediately before this line - Yoroshiku onegai itashimasu. Arigatou gozaimasu. Benjamin L. Russell --- jerzy.karczmarczuk@info.unicaen.fr wrote: > Chung-chieh Shan corrects me: > > >> PS. If you think that "arigato" is a genuine > Japanese word, well, check > >> how the appropriately translated word is spelled > in Portuguese... > > > > I'm not sure what you mean by "genuine", but I > suspect that whether > > "arigato" is genuine does not depend on > Portuguese. > > http://linguistlist.org/issues/12/12-1871.html > > http://linguistlist.org/issues/12/12-1906.html > > > Yes, it seems that I have been one more victim of > this red herring. > In the cited issues of the linguistlist there is a > nice discussion of that > topic. It should be more widely known entre a gente > falando portugues. > Vou calar a boca... > > Gomen nasai. > > Jerzy Karczmarczuk > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From alfonso.acosta at gmail.com Fri Feb 1 07:00:05 2008 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Fri Feb 1 06:59:20 2008 Subject: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?) In-Reply-To: <200801312335.21615.g9ks157k@acme.softbase.org> References: <6a7c66fc0801310302p6bdee4adm6cf6a2778772ecbf@mail.gmail.com> <200801312335.21615.g9ks157k@acme.softbase.org> Message-ID: <6a7c66fc0802010400g71094d4fy66cc40483de699dc@mail.gmail.com> On Jan 31, 2008 11:35 PM, Wolfgang Jeltsch wrote: > Am Donnerstag, 31. Januar 2008 18:30 schrieb Dominic Steinitz: > > Look at > > > > http://sneezy.cs.nott.ac.uk/fun/feb-07/jeremy-slides.pdf > > This is essentially what I had in mind. While Oleg's implementation needs > a "thrusted core", the GADT solution doesn't. True. However using GADTs doesn't allow to internally make use of Arrays, which (tell me if I'm wrong) are likely to be faster than the naive GADT implementation. Actually the GADT implementation you proposed fits nicely with the Vector definition already used in my EDSL (it is isomorphic actually), but efficiency could be an issue. > Some words on the representation of decimal numbers as types. While the > representation with types of the form D1 (D2 (D3 Sz)) has the advantage of > allowing numbers of arbitrary size, it has the disadvantage of a growing > number of parantheses. In my opinion, it would be nicer to have somethink > like D1 :- D2 :- D9 :- () with a right-associative operator :-. We could > even build the digit list the other way round?() :- D1 :- D2 :- D9?using a > left-associative :-. With the latter representation, we wouldn't need to > reverse digit sequences when adding numbers. Right, I agree. I think we should use the arbitrary-size implementation (actually, how arbitrary is it? what's the limit of GHC, if any?). To make it friendlier for the end user I thought about defining aliases for lets say the first 10000 numbers using Template Haskell. That could even make error reports friendlier (not sure to what point though). What do you think? So, we'll be making two separate libraries then. We should think about names. What about FixedVector for the vector library and DecTypArith (maybe too long) or DecTypes for the type-level decimal arithmetic library? I'll put my hands dirty once we agree on this. Cheers, Fons From alfonso.acosta at gmail.com Fri Feb 1 07:09:03 2008 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Fri Feb 1 07:08:17 2008 Subject: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?) In-Reply-To: <6a7c66fc0802010400g71094d4fy66cc40483de699dc@mail.gmail.com> References: <6a7c66fc0801310302p6bdee4adm6cf6a2778772ecbf@mail.gmail.com> <200801312335.21615.g9ks157k@acme.softbase.org> <6a7c66fc0802010400g71094d4fy66cc40483de699dc@mail.gmail.com> Message-ID: <6a7c66fc0802010409i635c47e2xe7c34e69007dd436@mail.gmail.com> > What about FixedVector for the vector library and DecTypArith (maybe > too long) or DecTypes for the type-level decimal arithmetic library? Actually it would maybe be better to create common high-level interface that could include unary, binary and decimal arithmetic so that the library could be easily reused in other projects (people like Bjorn, seem to be using the unary implementation). I don't know if it would be feasible though. From jules at jellybean.co.uk Fri Feb 1 07:15:35 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Fri Feb 1 07:14:51 2008 Subject: [Haskell-cafe] Simple network client In-Reply-To: <86506D5E-1C88-48F9-B8D2-606EA0030F43@fastmail.fm> References: <200801291212.02144.t.h@gmx.info><47A0678F.1070507@jellybean.co.uk> <002201c86348$911cad70$b3560850$@be> <125EACD0CAE4D24ABDB4D148C4593DA9049E926C@GBLONXMB02.corp.amvescap.net> <47A19382.9010006@phil.uu.nl> <86506D5E-1C88-48F9-B8D2-606EA0030F43@fastmail.fm> Message-ID: <47A30D67.9050604@jellybean.co.uk> Jonathan Cast wrote: > On 31 Jan 2008, at 1:23 AM, Reinier Lamers wrote: > >> Bayley, Alistair wrote: >>> More than one person has posted previously about the flaws and traps >>> of lazy IO. A common position seems to be "don't do lazy IO". >>> >> Still, when I was browsing the Haskell' wiki a few days ago, I >> couldn't find any proposal to remove lazy I/O or move it into some >> special System.IO.Lazy (or >> System.IO.UnsafeEvilFunctionsThatSacrificeBabies) ... > > Sacrificing babies is not a unique characteristic of lazy IO, of course; > it's true of any file IO on a non-versioning file system. However you can contain the pain if it's in the IO monad, and be in no worse situation than conventional languages. If the pain is unsafeInterleaved all over the place, then you actually *are* in a worse situation. ObHaskell' : lazy IO shouldn't be in any haskell standard, since it's not referentially transparent. It should be a powerful but dangerous feature enabled by certain implementations in an implementation specfic way. (unsafeInterleaveIO itself is not haskel98, I'm fairly sure) Jules From r.kelsall at millstream.com Fri Feb 1 08:15:54 2008 From: r.kelsall at millstream.com (Richard Kelsall) Date: Fri Feb 1 08:15:13 2008 Subject: Cryptographic hash uniquness (was [Haskell-cafe] Simple network client) In-Reply-To: <151242831.20080131202417@gmail.com> References: <151242831.20080131202417@gmail.com> Message-ID: <47A31B8A.1000300@millstream.com> Bulat Ziganshin wrote: > Hello Peter, > > Thursday, January 31, 2008, 8:01:36 PM, you wrote: > >> files with different content generating the same hash)... My >> intuition told me that the odds of two cryptographic hashes (on >> meaningful content) colliding was much less than the earth being >> destroyed by an asteroid... But this is just intuition... What does >> computer science tell us about this? > > you may be interested to know that widely used rsync algorithms relies > on 128-bit hashes and its author speculated about its reliability: > > http://samba.org/~tridge/phd_thesis.pdf > Interesting paper. Thank you. I had a quick read of the bit relating to hashes and my understanding is this. He uses a weak, quick and simple hash to deal with 99.99% (I invented that percentage) of cases - if the hash is different we know the files are definitely different - if the hash collides he then does a strong, slow, secure hash and relies on this as the answer. But he's relying on the strong hash rather than doing a byte by byte comparison because there is a major cost (a network transmission of the file) to doing the proper byte by byte comparison. If you had both files accessible at a low cost it might be better to byte by byte compare them when you get a collision rather than use the strong hash. The right approach may be to assume that collisions will occur and cater for this properly in the program somehow. A good tip for testing this sort of thing is to have the length of the hash (maximum size of the array or whatever you want to test) as a parameter that you can turn down to a very low value to induce collisions (overflows etc) to see whether the program still works. And then turn it back up for live use. A cryptographic hash appears as a completely random function of the input so the likelihood of a collision is simply 2^(bits in hash). Richard. From loup.vaillant at gmail.com Fri Feb 1 09:03:05 2008 From: loup.vaillant at gmail.com (Loup Vaillant) Date: Fri Feb 1 09:02:22 2008 Subject: [Haskell-cafe] Who started 42, and when? In-Reply-To: <6f9f8f4a0802010557g56c7457dx4227131fe63689a6@mail.gmail.com> References: <6f9f8f4a0802010557g56c7457dx4227131fe63689a6@mail.gmail.com> Message-ID: <6f9f8f4a0802010603h4d091167p10e21a64c820b791@mail.gmail.com> I have read quite a lot of Haskell papers, lately, and noticed that the number 42 appeared quite often, in informal tutorials as well as in very serious research papers. No wonder Haskell is the Answer to The Great Question of Life, The Universe, and Everything, but I would like to know who started this, and when. Google wasn't much help, and I can't believe it's coincidence --hence this email. I hope I didn't opened some Pandora box. :-) Cheers, Loup From dbueno at gmail.com Fri Feb 1 09:10:50 2008 From: dbueno at gmail.com (Denis Bueno) Date: Fri Feb 1 09:10:05 2008 Subject: [Haskell-cafe] Who started 42, and when? In-Reply-To: <6f9f8f4a0802010603h4d091167p10e21a64c820b791@mail.gmail.com> References: <6f9f8f4a0802010557g56c7457dx4227131fe63689a6@mail.gmail.com> <6f9f8f4a0802010603h4d091167p10e21a64c820b791@mail.gmail.com> Message-ID: <6dbd4d000802010610v7744440bkad1182e9a69c985d@mail.gmail.com> On Fri, Feb 1, 2008 at 9:03 AM, Loup Vaillant wrote: > I have read quite a lot of Haskell papers, lately, and noticed that > the number 42 appeared quite often, in informal tutorials as well as > in very serious research papers. No wonder Haskell is the Answer to > The Great Question of Life, The Universe, and Everything, but I would > like to know who started this, and when. I believe it was Douglas Adams, author of the "trilogy" "Hitchhiker's Guide to the Galaxy". You may enjoy reading it, if you haven't. -- Denis From haskell at list.mightyreason.com Fri Feb 1 09:18:05 2008 From: haskell at list.mightyreason.com (ChrisK) Date: Fri Feb 1 09:17:29 2008 Subject: [Haskell-cafe] Re: A handy little consequence of the Cont monad In-Reply-To: <89ca3d1f0801312109k718f60a9maeef1c5e1025cc28@mail.gmail.com> References: <89ca3d1f0801312109k718f60a9maeef1c5e1025cc28@mail.gmail.com> Message-ID: The "bit of a mess" that comes from avoiding monads is (my version): > import Foreign.Marshal.Array(withArray0) > import Foreign.Ptr(nullPtr,Ptr) > import Foreign.C.String(withCString,CString) This uses withCString in order of the supplied strings, and a difference list ([CString]->[CString]) initialized by "id" to assemble the [CString]. This is the laziest way to proceed. > acquireInOrder :: [String] -> (Ptr CString -> IO a) -> IO a > acquireInOrder strings act = > foldr (\s cs'io'a -> > (\cs -> > withCString s (\c -> cs'io'a (cs . (c:)) > ) > ) > ) > (\cs -> > withArray0 nullPtr (cs []) act > ) > strings > id This uses in withCString in reversed order of the supplied strings, and normal list ([CString]) initialized by "[]" to assemble the [CString]. This is not as lazy since it needs to go to the end of the supplied list for the first IO action. > acquireInRerverseOrder :: [String] -> (Ptr CString -> IO a) -> IO a > acquireInRerverseOrder strings act = > foldl (\cs'io'a s -> > (\cs -> > withCString s (\c -> cs'io'a (c:cs) > ) > ) > ) > (\cs -> > withArray0 nullPtr cs act > ) > strings > [] Cale Gibbard wrote: > Hello, > > Today on #haskell, resiak was asking about a clean way to write the > function which allocates an array of CStrings using withCString and > withArray0 to produce a new with* style function. I came up with the > following: > > nest :: [(r -> a) -> a] -> ([r] -> a) -> a > nest xs = runCont (sequence (map Cont xs)) > > withCStringArray0 :: [String] -> (Ptr CString -> IO a) -> IO a > withCStringArray0 strings act = nest (map withCString strings) > (\rs -> withArray0 nullPtr rs act) > > Originally, I'd written nest without using the Cont monad, which was a > bit of a mess by comparison, then noticed that its type was quite > suggestive. > > Clearly, it would be more generally useful whenever you have a bunch > of with-style functions for managing the allocation of resources, and > would like to turn them into a single with-style function providing a > list of the acquired resources. > > - Cale From cconway at cs.nyu.edu Fri Feb 1 09:18:50 2008 From: cconway at cs.nyu.edu (Christopher L Conway) Date: Fri Feb 1 09:18:09 2008 Subject: [Haskell-cafe] Who started 42, and when? In-Reply-To: <6f9f8f4a0802010603h4d091167p10e21a64c820b791@mail.gmail.com> References: <6f9f8f4a0802010557g56c7457dx4227131fe63689a6@mail.gmail.com> <6f9f8f4a0802010603h4d091167p10e21a64c820b791@mail.gmail.com> Message-ID: <4a051d930802010618x614bef69na3a8e380bc3e1f98@mail.gmail.com> Loup, This is not unique to the Haskell community. I suspect the arbitrary constant 42 has been appearing unexplained in research papers for as long as there have been computer scientists who were sci-fi geeks (absolutely no offense intended to geeks ;-). It would be very difficult indeed to figure out who did this first, without some highly dedicated library research. Chris On Feb 1, 2008 9:03 AM, Loup Vaillant wrote: > I have read quite a lot of Haskell papers, lately, and noticed that > the number 42 appeared quite often, in informal tutorials as well as > in very serious research papers. No wonder Haskell is the Answer to > The Great Question of Life, The Universe, and Everything, but I would > like to know who started this, and when. > > Google wasn't much help, and I can't believe it's coincidence --hence > this email. I hope I didn't opened some Pandora box. :-) > > Cheers, > Loup > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From voigt at tcs.inf.tu-dresden.de Fri Feb 1 09:19:31 2008 From: voigt at tcs.inf.tu-dresden.de (Janis Voigtlaender) Date: Fri Feb 1 09:18:47 2008 Subject: [Haskell-cafe] Who started 42, and when? In-Reply-To: <6dbd4d000802010610v7744440bkad1182e9a69c985d@mail.gmail.com> References: <6f9f8f4a0802010557g56c7457dx4227131fe63689a6@mail.gmail.com> <6f9f8f4a0802010603h4d091167p10e21a64c820b791@mail.gmail.com> <6dbd4d000802010610v7744440bkad1182e9a69c985d@mail.gmail.com> Message-ID: <47A32A73.4@tcs.inf.tu-dresden.de> Denis Bueno wrote: > On Fri, Feb 1, 2008 at 9:03 AM, Loup Vaillant wrote: > >>I have read quite a lot of Haskell papers, lately, and noticed that >> the number 42 appeared quite often, in informal tutorials as well as >> in very serious research papers. No wonder Haskell is the Answer to >> The Great Question of Life, The Universe, and Everything, but I would >> like to know who started this, and when. > > > I believe it was Douglas Adams, author of the "trilogy" "Hitchhiker's > Guide to the Galaxy". You may enjoy reading it, if you haven't. I think Loup is aware of the hitchhiker books (see the reference to the Great Question of ... Everything). So unless Douglas Adams wrote some Haskell papers I am not aware of, the original question is still open ;-) Happy weekend... Janis. -- Dr. Janis Voigtlaender http://wwwtcs.inf.tu-dresden.de/~voigt/ mailto:voigt@tcs.inf.tu-dresden.de From loup.vaillant at gmail.com Fri Feb 1 09:27:45 2008 From: loup.vaillant at gmail.com (Loup Vaillant) Date: Fri Feb 1 09:26:59 2008 Subject: [Haskell-cafe] Who started 42, and when? In-Reply-To: <4a051d930802010618x614bef69na3a8e380bc3e1f98@mail.gmail.com> References: <6f9f8f4a0802010557g56c7457dx4227131fe63689a6@mail.gmail.com> <6f9f8f4a0802010603h4d091167p10e21a64c820b791@mail.gmail.com> <4a051d930802010618x614bef69na3a8e380bc3e1f98@mail.gmail.com> Message-ID: <6f9f8f4a0802010627q3ecaf2efia1a6f0ef0668b20e@mail.gmail.com> 2008/2/1, Christopher L Conway : > Loup, > > This is not unique to the Haskell community. I suspect the arbitrary > constant 42 has been appearing unexplained in research papers for as > long as there have been computer scientists who were sci-fi geeks > (absolutely no offense intended to geeks ;-). It would be very > difficult indeed to figure out who did this first, without some highly > dedicated library research. I suspected this. Just that I didn't noticed 42 but in Haskell papers. Maybe this is just a bias due to my recent interests. I should check some C/C++/Lisp/Ocaml papers. About the library search, Maybe it is possible to try a giant "grep" on all papers in ACM Portal, or CiteSeer? Loup From cconway at cs.nyu.edu Fri Feb 1 09:32:49 2008 From: cconway at cs.nyu.edu (Christopher L Conway) Date: Fri Feb 1 09:32:05 2008 Subject: [Haskell-cafe] Who started 42, and when? In-Reply-To: <6f9f8f4a0802010627q3ecaf2efia1a6f0ef0668b20e@mail.gmail.com> References: <6f9f8f4a0802010557g56c7457dx4227131fe63689a6@mail.gmail.com> <6f9f8f4a0802010603h4d091167p10e21a64c820b791@mail.gmail.com> <4a051d930802010618x614bef69na3a8e380bc3e1f98@mail.gmail.com> <6f9f8f4a0802010627q3ecaf2efia1a6f0ef0668b20e@mail.gmail.com> Message-ID: <4a051d930802010632n61c51b70wb67cb6821a60bec3@mail.gmail.com> On Feb 1, 2008 9:27 AM, Loup Vaillant wrote: > I suspected this. Just that I didn't noticed 42 but in Haskell papers. > Maybe this is just a bias due to my recent interests. I should check > some C/C++/Lisp/Ocaml papers. > > About the library search, Maybe it is possible to try a giant "grep" > on all papers in ACM Portal, or CiteSeer? I tried this briefly on the ACM. You need to be able to exclude citations, footnotes, volume numbers, etc., and their "Advanced Search" is not quite that advanced. :-) Chris From alfonso.acosta at gmail.com Fri Feb 1 09:41:10 2008 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Fri Feb 1 09:40:24 2008 Subject: [Haskell-cafe] fast graph algorithms without object identities In-Reply-To: <30150267-9896-4E99-BFE8-A7FCA587215C@alum.mit.edu> References: <30150267-9896-4E99-BFE8-A7FCA587215C@alum.mit.edu> Message-ID: <6a7c66fc0802010641u43c7f905l14f6dddbbd388111@mail.gmail.com> You'd probably be interested to read http://www.cs.chalmers.se/~koen/pubs/entry-asian99-lava.html On Jan 31, 2008 9:56 PM, Jan-Willem Maessen wrote: > > On Jan 31, 2008, at 5:39 AM, Henning Thielemann wrote: > > > > > It seems that algorithms on graphs can be implemented particularly > > efficient in low-level languages with pointers and in-place updates. > > E.g. > > topological sort needs only linear time, provided that dereferencing > > pointers requires constant time. I could simulate pointer > > dereferencings > > and pointer updates by Map yielding linear logarithmic time for > > topological sort. I wonder if it is possible to write a linear time > > topological sort using lazy evaluation, since the runtime system of > > Haskell implementations is a graph processor based on pointers. > > If so, I'd love to see this written up; I think it may be publishable > if it isn't published already. > > Note that even using ST techniques can take more than linear time, > given an arbitrary purely-functionally-defined graph as input. We > can't (eg) assume that each node contains a reference, or that they > are densely numbered, so we end up having to look them up in some > fashion (though using a hash table can be reasonably quick if we > uniquely number nodes). > > -Jan-Willem Maessen > > > > > > _______________________________________________ > > Haskell-Cafe mailing list > > Haskell-Cafe@haskell.org > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From dbueno at gmail.com Fri Feb 1 09:41:15 2008 From: dbueno at gmail.com (Denis Bueno) Date: Fri Feb 1 09:40:32 2008 Subject: [Haskell-cafe] Who started 42, and when? In-Reply-To: <47A32A73.4@tcs.inf.tu-dresden.de> References: <6f9f8f4a0802010557g56c7457dx4227131fe63689a6@mail.gmail.com> <6f9f8f4a0802010603h4d091167p10e21a64c820b791@mail.gmail.com> <6dbd4d000802010610v7744440bkad1182e9a69c985d@mail.gmail.com> <47A32A73.4@tcs.inf.tu-dresden.de> Message-ID: <6dbd4d000802010641t686124c1l150f31c0c5b5ef06@mail.gmail.com> On Fri, Feb 1, 2008 at 9:19 AM, Janis Voigtlaender wrote: > I think Loup is aware of the hitchhiker books (see the reference to the > Great Question of ... Everything). Ah, I didn't read that correctly. I assumed that something he read something that had described Haskell as the answer to Life, the Universe, and Everything. Sorry about that. -- Denis From molyneux at kingston.ac.uk Fri Feb 1 10:24:02 2008 From: molyneux at kingston.ac.uk (Phil Molyneux) Date: Fri Feb 1 10:23:22 2008 Subject: [Haskell-cafe] Who started 42, and when? In-Reply-To: <6f9f8f4a0802010603h4d091167p10e21a64c820b791@mail.gmail.com> References: <6f9f8f4a0802010557g56c7457dx4227131fe63689a6@mail.gmail.com> <6f9f8f4a0802010603h4d091167p10e21a64c820b791@mail.gmail.com> Message-ID: <40190312-5D60-48CE-A04D-6894DC984E57@kingston.ac.uk> Hi --- The arbitrary constant was made popular by Douglas Adams in the mid-1970s radio series ``A Hitchhikers Guide to the Galaxy'' (a trilogy in 4 parts) --- however it does have a basis in the standard model of physics --- a paper in Phys.Rev. of the early 1970s described the unification of the Electro-Weak and Strong nuclear forces --- the arbitrary constant (of nearly) 42 appears in the calculations. I forget the original paper but if you get hold of Frank Close ``The Cosmic Onion'' a graph reproduces the result. I met Douglas Adams once at a book signing and asked him how he got hold of the Phys.Rev. paper so early. Technically he should have written that ``42 is the answer to life, the universe and everything except for gravity and a few other arbitrary constants'' Adams was interested in computing --- I think his reaction to being told about functional programming was to wonder what non-functional programming might be. Phil On 1 Feb 2008, at 14:03, Loup Vaillant wrote: > I have read quite a lot of Haskell papers, lately, and noticed that > the number 42 appeared quite often, in informal tutorials as well as > in very serious research papers. No wonder Haskell is the Answer to > The Great Question of Life, The Universe, and Everything, but I would > like to know who started this, and when. > > Google wasn't much help, and I can't believe it's coincidence --hence > this email. I hope I didn't opened some Pandora box. :-) > > Cheers, > Loup > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > This email has been scanned for all viruses by the MessageLabs Email > Security System. This email has been scanned for all viruses by the MessageLabs Email Security System. From colin at colina.demon.co.uk Fri Feb 1 10:35:13 2008 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Fri Feb 1 10:34:29 2008 Subject: [Haskell-cafe] Who started 42, and when? In-Reply-To: <40190312-5D60-48CE-A04D-6894DC984E57@kingston.ac.uk> (Phil Molyneux's message of "Fri\, 1 Feb 2008 15\:24\:02 +0000") References: <6f9f8f4a0802010557g56c7457dx4227131fe63689a6@mail.gmail.com> <6f9f8f4a0802010603h4d091167p10e21a64c820b791@mail.gmail.com> <40190312-5D60-48CE-A04D-6894DC984E57@kingston.ac.uk> Message-ID: >>>>> "Phil" == Phil Molyneux writes: Phil> Adams was interested in computing --- I think his reaction Phil> to being told about functional programming was to wonder Phil> what non-functional programming might be. Curiously, that was my reaction too when i first heard of the term (from a university student who was complaining that it was too hard). -- Colin Adams Preston Lancashire From catamorphism at gmail.com Fri Feb 1 11:10:15 2008 From: catamorphism at gmail.com (Tim Chevalier) Date: Fri Feb 1 11:09:31 2008 Subject: [Haskell-cafe] Who started 42, and when? In-Reply-To: References: <6f9f8f4a0802010557g56c7457dx4227131fe63689a6@mail.gmail.com> <6f9f8f4a0802010603h4d091167p10e21a64c820b791@mail.gmail.com> <40190312-5D60-48CE-A04D-6894DC984E57@kingston.ac.uk> Message-ID: <4683d9370802010810t44143df5p6bcd9b00efbb0936@mail.gmail.com> To pre-empt the next couple of questions, the numbers 17 and 23 are from _The Illuminatus! Trilogy_ by Robert Shea and Robert Anton Wilson, and the number 37 is from the Jersey Trilogy of movies by Kevin Smith. Cheers, Tim -- Tim Chevalier * http://cs.pdx.edu/~tjc * Often in error, never in doubt "I'm a nonbeliever, but I believe in your smile." -- Laura Nyro From bjorn.buckwalter at gmail.com Fri Feb 1 11:23:55 2008 From: bjorn.buckwalter at gmail.com (Bjorn Buckwalter) Date: Fri Feb 1 11:23:16 2008 Subject: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?) References: <6a7c66fc0801310302p6bdee4adm6cf6a2778772ecbf@mail.gmail.com> <200801312335.21615.g9ks157k@acme.softbase.org> <6a7c66fc0802010400g71094d4fy66cc40483de699dc@mail.gmail.com> <6a7c66fc0802010409i635c47e2xe7c34e69007dd436@mail.gmail.com> Message-ID: Alfonso Acosta gmail.com> writes: > Actually it would maybe be better to create common high-level > interface that could include unary, binary and decimal arithmetic so > that the library could be easily reused in other projects (people like > Bjorn, seem to be using the unary implementation). I don't know if it > would be feasible though. My reason for going with unary implementation was that it seemed to be the easiest and less tedious to implement. But is sure does make the error messages less friendly. It also limits the magnitude of the numbers quite severely unless one bumps up the type checker stack size. From the source code: "The practical size of the NumTypes is limited by the type checker stack. If the NumTypes grow too large (which can happen quickly with multiplication) an error message similar to the following will be emitted: Context reduction stack overflow; size = 20 Use -fcontext-stack=N to increase stack size to N This situation could concievably be mitigated significantly by using e.g. a binary representation of integers rather than Peano numbers." For my use (keeping track of physical dimensions) this hasn't been a problem. If Naturals had been sufficient for me I wouldn't have done my own implementation (I'm unaware of any other implementation of Integers). And there is certainly a lot of value to the clearer error messages from a decimal representation. Concerning whether or not there is any value in being able to change the representation of the type- level naturals in your library, my guess is that the value wouldn't be all that great. As I mentioned I use my implementation for tracking physical dimensions and HList's HNats for constraining vector dimensions but this isn't a problem since I cannot conceive of any reason why I would want to intermix the two. Of course, other usage scenarios exist where there would be a desire to intermix the vector dimensions with something else...? So sure, if you can abstract the representation away by all means do it. But I wouldn't go out of my way or impair the rest of the library to achieve this. Hope this helps, Bjorn From jmaessen at alum.mit.edu Fri Feb 1 11:28:12 2008 From: jmaessen at alum.mit.edu (Jan-Willem Maessen) Date: Fri Feb 1 11:27:32 2008 Subject: [Haskell-cafe] fast graph algorithms without object identities In-Reply-To: <6a7c66fc0802010641u43c7f905l14f6dddbbd388111@mail.gmail.com> References: <30150267-9896-4E99-BFE8-A7FCA587215C@alum.mit.edu> <6a7c66fc0802010641u43c7f905l14f6dddbbd388111@mail.gmail.com> Message-ID: <009AAE5D-A47A-45D0-AC5D-3C1269500D9E@alum.mit.edu> On Feb 1, 2008, at 9:41 AM, Alfonso Acosta wrote: > You'd probably be interested to read > http://www.cs.chalmers.se/~koen/pubs/entry-asian99-lava.html It is indeed an interesting paper (that I've read and referred to several times over the years). But it's tricky to get right in practice! And sadly, while it solves the problem of sharing (or object equivalence) it doesn't give us some sort of total order or hash key, so there's no way to efficiently associate transient mutable state uniquely with each reference we encounter. For that we need one of the other solutions discussed and rejected. This is why Data.Unique provides a pure hashUnique function. The best option I know of here to get the desired time bounds with a purely-functional abstraction is to use a splittable supply of unique labels (which can be encapsulated in a monad if we like), then use ST to associate a hash table of references with the graph nodes while traversing the graph. -Jan From wnoise at ofb.net Fri Feb 1 14:27:18 2008 From: wnoise at ofb.net (Aaron Denney) Date: Fri Feb 1 14:26:49 2008 Subject: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?) References: <6a7c66fc0801310302p6bdee4adm6cf6a2778772ecbf@mail.gmail.com> <200801312335.21615.g9ks157k@acme.softbase.org> <6a7c66fc0802010400g71094d4fy66cc40483de699dc@mail.gmail.com> <6a7c66fc0802010409i635c47e2xe7c34e69007dd436@mail.gmail.com> Message-ID: On 2008-02-01, Bjorn Buckwalter wrote: > If Naturals had been sufficient for me I wouldn't have done my own > implementation (I'm unaware of any other implementation of Integers). > And there is certainly a lot of value to the clearer error messages > from a decimal representation. I did a balanced-base-three (digits are 0, and +- 1) representation to get negative "decimals". Again, for a proof-of-concept dimensional analysis arithmetic. No problem with the stack, but the error messages are still less than clear. -- Aaron Denney -><- From lgreg.meredith at biosimilarity.com Fri Feb 1 14:55:51 2008 From: lgreg.meredith at biosimilarity.com (Greg Meredith) Date: Fri Feb 1 14:55:07 2008 Subject: [Haskell-cafe] NW Functional Programming Interest Group Message-ID: <5de3f5ca0802011155l771cc649wa0e671bbe3abe364@mail.gmail.com> All, Apologies for multiple listings. A small cadre of us are organizing a Northwest Functional Programming Interest Group (hey... NWFPIG, that's kinda funny). Our first official meeting is at the The Seattle Public Library 1000 - 4th Ave. Seattle, WA 98104 from 17:00 - 18:00 on February 20th. On the first meeting's agenda we'll be - giving people who are interested in or actively using FP for work or play a chance to meet - seeking to build up a pipeline of presentations and guest speakers - trying to keep organizational mishigosh to a minimum Hope to see you there. Monadically yours, --greg -- L.G. Meredith Managing Partner Biosimilarity LLC 806 55th St NE Seattle, WA 98105 +1 206.650.3740 http://biosimilarity.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080201/c54cf502/attachment.htm From jgbailey at gmail.com Fri Feb 1 15:36:44 2008 From: jgbailey at gmail.com (Justin Bailey) Date: Fri Feb 1 15:35:57 2008 Subject: [Haskell-cafe] Re: [Haskell] NW Functional Programming Interest Group In-Reply-To: <5de3f5ca0802011155l771cc649wa0e671bbe3abe364@mail.gmail.com> References: <5de3f5ca0802011155l771cc649wa0e671bbe3abe364@mail.gmail.com> Message-ID: If Seattle is too far away, Portland has its own recently formed FP group, PDXFP: http://groups.google.com/group/pdxfunc So far we're meeting every 2nd Monday of the month at CubeSpace on 6th & Grand. Justin From vigalchin at gmail.com Fri Feb 1 16:01:52 2008 From: vigalchin at gmail.com (Galchin Vasili) Date: Fri Feb 1 16:01:12 2008 Subject: [Haskell-cafe] reading from the cdrom drive on Red Hat Message-ID: <5ae4f2ba0802011301k6e6cda09ya13f6850c8f48078@mail.gmail.com> Hello, I wrote a simple program to read the contents of a cdrom: module Main where import Text.Printf import System.IO import System.Posix.Types import System.Posix.IO main = do fd <- openFd "/dev/cdrom" ReadOnly Nothing defaultFileFlags readCdRom fd 4096 closeFd fd readCdRom fd byteCount = do (buf, actualByteCount) = fdRead fd bytecount readCdRom fd byteCount When it executed it read thousands of 4096 blocks as I expected. It then got a "hardware error" which I suspect was the "end of the CD", i.e. the begininng of the "unlasered" part of the CD. Is there a better and more graceful way to detect and handle "end of data"? Thanks, ,Vasili -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080201/3a279362/attachment.htm From g9ks157k at acme.softbase.org Fri Feb 1 16:05:16 2008 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Fri Feb 1 16:04:42 2008 Subject: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?) In-Reply-To: <47A29BDC.9010709@charter.net> References: <6a7c66fc0801310302p6bdee4adm6cf6a2778772ecbf@mail.gmail.com> <200801312335.21615.g9ks157k@acme.softbase.org> <47A29BDC.9010709@charter.net> Message-ID: <200802012205.16432.g9ks157k@acme.softbase.org> Am Freitag, 1. Februar 2008 05:11 schrieben Sie: > Wolfgang Jeltsch wrote: > > Well, the representation (D1,D2,D9) might be considered more readable. > > It has the disadvantage of a fixed maximum size for the numbers. Which > > takes me to a point I had already considered some time ago: Wouldn?t it > > be good if we had just a type > > > > data Pair val1 val2 = Pair val1 val2 > > > > and if then (val1,val2,?,valn) would just be syntactic sugar for this: > > > > val1 `Pair` (val2 `Pair` (?(valn `Pair` ())?)) > > I've thought of that too.. besides the asymmetry, the presence of > _|_/seq makes them actually not equivalent though, unfortunately > > ~Isaac With Ryan?s proposal (using strictness annotations) the new representation should be equivalent to the old one. Or am I missing something? Best wishes, Wolfgang From derek.a.elkins at gmail.com Fri Feb 1 16:27:06 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Fri Feb 1 16:26:26 2008 Subject: [Haskell-cafe] A handy little consequence of the Cont monad In-Reply-To: <89ca3d1f0801312109k718f60a9maeef1c5e1025cc28@mail.gmail.com> References: <89ca3d1f0801312109k718f60a9maeef1c5e1025cc28@mail.gmail.com> Message-ID: <1201901226.5496.79.camel@derek-laptop> On Fri, 2008-02-01 at 00:09 -0500, Cale Gibbard wrote: > Hello, > > Today on #haskell, resiak was asking about a clean way to write the > function which allocates an array of CStrings using withCString and > withArray0 to produce a new with* style function. I came up with the > following: > > nest :: [(r -> a) -> a] -> ([r] -> a) -> a > nest xs = runCont (sequence (map Cont xs)) This is what you write after all that time on #haskell? nest = runCont . sequence . map Cont From agl at imperialviolet.org Fri Feb 1 16:28:06 2008 From: agl at imperialviolet.org (Adam Langley) Date: Fri Feb 1 16:27:20 2008 Subject: [Haskell-cafe] reading from the cdrom drive on Red Hat In-Reply-To: <5ae4f2ba0802011301k6e6cda09ya13f6850c8f48078@mail.gmail.com> References: <5ae4f2ba0802011301k6e6cda09ya13f6850c8f48078@mail.gmail.com> Message-ID: <396556a20802011328i61dd64fdp80e2fc3251a5490c@mail.gmail.com> 2008/2/1 Galchin Vasili : > I wrote a simple program to read the contents of a cdrom: (Note that this is a terribly inefficient way of reading large amounts of binary data. Of course, if this is just meant as an example, that's fine. Otherwise, see the struff about ByteStrings at http://www.haskell.org/haskellwiki/DealingWithBinaryData) The error you are seeing comes from the operating system. You could run the resulting Haskell program under strace to see the exact error, but what's happening is that the kernel is getting an error from the CD drive itself. This is pretty much unique to CDs I guess. If you were reading a hard drive, the kernel knows exactly how large the disk is (see /proc/partitions) and would return EOF (zero bytes). As an aside, hitting EOF in your code would result in an infinite loop, since you don't handle actualByteCount == 0. You can catch and handle the resulting exception with the functions in: http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641 From g9ks157k at acme.softbase.org Fri Feb 1 16:32:16 2008 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Fri Feb 1 16:31:35 2008 Subject: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?) In-Reply-To: <6a7c66fc0802010400g71094d4fy66cc40483de699dc@mail.gmail.com> References: <6a7c66fc0801310302p6bdee4adm6cf6a2778772ecbf@mail.gmail.com> <200801312335.21615.g9ks157k@acme.softbase.org> <6a7c66fc0802010400g71094d4fy66cc40483de699dc@mail.gmail.com> Message-ID: <200802012232.16922.g9ks157k@acme.softbase.org> Am Freitag, 1. Februar 2008 13:00 schrieb Alfonso Acosta: > On Jan 31, 2008 11:35 PM, Wolfgang Jeltsch wrote: > > Am Donnerstag, 31. Januar 2008 18:30 schrieb Dominic Steinitz: > > > Look at > > > > > > http://sneezy.cs.nott.ac.uk/fun/feb-07/jeremy-slides.pdf > > > > This is essentially what I had in mind. While Oleg's implementation > > needs a "thrusted core", the GADT solution doesn't. > > True. However using GADTs doesn't allow to internally make use of > Arrays, which (tell me if I'm wrong) are likely to be faster than the > naive GADT implementation. It depends. My first GADT implementation is equivalent to the [] type and often [] is better than arrays. For example, if you read the contents of a file and process it with maps, filters, etc., [] is likely to give you constant space usage which arrays don?t. If you want to lookup elements by index, then arrays are better, of course. For my purpose, it would be fine to use a []-like implementation, I think. > [?] > > Some words on the representation of decimal numbers as types. While the > > representation with types of the form D1 (D2 (D3 Sz)) has the advantage > > of allowing numbers of arbitrary size, it has the disadvantage of a > > growing number of parantheses. In my opinion, it would be nicer to have > > somethink like D1 :- D2 :- D9 :- () with a right-associative operator :-. > > We could even build the digit list the other way round?() :- D1 :- D2 :- > > D9?using a left-associative :-. With the latter representation, we > > wouldn't need to reverse digit sequences when adding numbers. > > Right, I agree. I think we should use the arbitrary-size implementation So let?s use the representation with the left-associative :- (or whatever operator we might choose). > (actually, how arbitrary is it? what's the limit of GHC, if any?). Arbitrary enough, I think. If we don?t need lists with billions of elements, our representations will have less than 8 digits. > To make it friendlier for the end user I thought about defining > aliases for lets say the first 10000 numbers using Template Haskell. > That could even make error reports friendlier (not sure to what point > though). What do you think? I have no clear opinion about that at the moment. Maybe it?s okay to use the representation directly. This way, we don?t introduce a dependeny on the Template Haskell language extension (which is only supported by GHC), and the actual representation will occur in error messages anyway whenever the message shows a computed number. > So, we'll be making two separate libraries then. We should think about > names. > > What about FixedVector for the vector library and DecTypArith (maybe > too long) or DecTypes for the type-level decimal arithmetic library? Alas, there is an inconsistency in naming packages already. Some prefer names which are entirely lowercase, some prefer camel case. I prefer lowercase, with hyphens separating parts of the name. And I also don?t like unusual abbreviations like ?typ? (not much shorter than ?type?). To mention arithmetics is not so important. So maybe something like ?type-level-decimals?? Maybe it?s better to put different type-level programming things into a single package. Then we could name this package ?type-level? or something similar. We could start with our decimals. Other type-level things could be added later. I already have some code about type-level booleans. It?s not very sensible to put these few lines into a separate package. It might be nice if we had a general type-level programming package where I could put this code into. As for the name of the fixed-size list package, I have to say that I don?t like the term ?vector? in this context. A vector is actually something with addition and scalar multiplication defined on it. Maybe we should make also this package?s scope wider. What about something like ?safe-data? or similar? > I'll put my hands dirty once we agree on this. Great!! > Cheers, > > Fons Best wishes, Wolfgang From g9ks157k at acme.softbase.org Fri Feb 1 16:33:28 2008 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Fri Feb 1 16:32:43 2008 Subject: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?) In-Reply-To: <6a7c66fc0802010409i635c47e2xe7c34e69007dd436@mail.gmail.com> References: <6a7c66fc0801310302p6bdee4adm6cf6a2778772ecbf@mail.gmail.com> <6a7c66fc0802010400g71094d4fy66cc40483de699dc@mail.gmail.com> <6a7c66fc0802010409i635c47e2xe7c34e69007dd436@mail.gmail.com> Message-ID: <200802012233.28126.g9ks157k@acme.softbase.org> Am Freitag, 1. Februar 2008 13:09 schrieben Sie: > > What about FixedVector for the vector library and DecTypArith (maybe > > too long) or DecTypes for the type-level decimal arithmetic library? > > Actually it would maybe be better to create common high-level > interface that could include unary, binary and decimal arithmetic so > that the library could be easily reused in other projects (people like > Bjorn, seem to be using the unary implementation). I don't know if it > would be feasible though. I?d say, let?s start with the decimal thing. We can extend our package later if there?s a need to do this, can?t we? Best wishes, Wolfgang From bos at serpentine.com Fri Feb 1 16:42:08 2008 From: bos at serpentine.com (Bryan O'Sullivan) Date: Fri Feb 1 16:41:22 2008 Subject: [Haskell-cafe] reading from the cdrom drive on Red Hat In-Reply-To: <396556a20802011328i61dd64fdp80e2fc3251a5490c@mail.gmail.com> References: <5ae4f2ba0802011301k6e6cda09ya13f6850c8f48078@mail.gmail.com> <396556a20802011328i61dd64fdp80e2fc3251a5490c@mail.gmail.com> Message-ID: <47A39230.2090004@serpentine.com> Adam Langley wrote: > The error you are seeing comes from the operating system. No, it's the Haskell runtime turning a -1 return from read into an exception. You need to call hIsEOF to check whether you've hit EOF, then break out of the loop. References: <89ca3d1f0801312109k718f60a9maeef1c5e1025cc28@mail.gmail.com> <1201901226.5496.79.camel@derek-laptop> Message-ID: <20080201214858.GF31711@cs.cmu.edu> Not to start a flame war or religious debate, but I don't think that eta-expansions should be considered bad style. I realize that composition-style is good for certain types of reasoning, but fully eta-expanded code has an important legibility advantage: you can tell the shape of its type just by looking at it! Personally, I'd rather read the original version. -Dan On Feb01, Derek Elkins wrote: > On Fri, 2008-02-01 at 00:09 -0500, Cale Gibbard wrote: > > Hello, > > > > Today on #haskell, resiak was asking about a clean way to write the > > function which allocates an array of CStrings using withCString and > > withArray0 to produce a new with* style function. I came up with the > > following: > > > > nest :: [(r -> a) -> a] -> ([r] -> a) -> a > > nest xs = runCont (sequence (map Cont xs)) > > This is what you write after all that time on #haskell? > > nest = runCont . sequence . map Cont > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From agl at imperialviolet.org Fri Feb 1 16:49:43 2008 From: agl at imperialviolet.org (Adam Langley) Date: Fri Feb 1 16:48:56 2008 Subject: [Haskell-cafe] reading from the cdrom drive on Red Hat In-Reply-To: <47A39230.2090004@serpentine.com> References: <5ae4f2ba0802011301k6e6cda09ya13f6850c8f48078@mail.gmail.com> <396556a20802011328i61dd64fdp80e2fc3251a5490c@mail.gmail.com> <47A39230.2090004@serpentine.com> Message-ID: <396556a20802011349x266303f7x66a099e186b59e4a@mail.gmail.com> On Feb 1, 2008 1:42 PM, Bryan O'Sullivan wrote: > No, it's the Haskell runtime turning a -1 return from read into an > exception. You need to call hIsEOF to check whether you've hit EOF, > then break out of the loop. (assuming you meant 0, not -1) My bad, I thought that the Posix.IO stuff was a closer wrapping than that. It does, indeed, throw an exception on 0. How unfortunate. AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641 From vigalchin at gmail.com Fri Feb 1 16:54:54 2008 From: vigalchin at gmail.com (Galchin Vasili) Date: Fri Feb 1 16:54:08 2008 Subject: [Haskell-cafe] reading from the cdrom drive on Red Hat In-Reply-To: <396556a20802011349x266303f7x66a099e186b59e4a@mail.gmail.com> References: <5ae4f2ba0802011301k6e6cda09ya13f6850c8f48078@mail.gmail.com> <396556a20802011328i61dd64fdp80e2fc3251a5490c@mail.gmail.com> <47A39230.2090004@serpentine.com> <396556a20802011349x266303f7x66a099e186b59e4a@mail.gmail.com> Message-ID: <5ae4f2ba0802011354x3d72d384xd1fa5caf4770ae78@mail.gmail.com> Thank you Adam and Bradley. My program is my getting a feel of how to open a Linux and do "block" reads. Just conceptual Vasili On 2/1/08, Adam Langley wrote: > > On Feb 1, 2008 1:42 PM, Bryan O'Sullivan wrote: > > No, it's the Haskell runtime turning a -1 return from read into an > > exception. You need to call hIsEOF to check whether you've hit EOF, > > then break out of the loop. > > (assuming you meant 0, not -1) > > My bad, I thought that the Posix.IO stuff was a closer wrapping than > that. It does, indeed, throw an exception on 0. How unfortunate. > > > AGL > > > -- > Adam Langley agl@imperialviolet.org > http://www.imperialviolet.org 650-283-9641 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080201/3ed7117a/attachment.htm From answer at tnoo.net Fri Feb 1 10:56:08 2008 From: answer at tnoo.net (Martin =?iso-8859-1?Q?L=FCthi?=) Date: Fri Feb 1 17:04:19 2008 Subject: [Haskell-cafe] Re: Who started 42, and when? References: <6f9f8f4a0802010557g56c7457dx4227131fe63689a6@mail.gmail.com> <6f9f8f4a0802010603h4d091167p10e21a64c820b791@mail.gmail.com> <40190312-5D60-48CE-A04D-6894DC984E57@kingston.ac.uk> Message-ID: <871w7wacx3.fsf@tnoo.net> Hi Phil Molyneux writes: > Hi --- The arbitrary constant was made popular by Douglas Adams in the > mid-1970s radio series ``A Hitchhikers Guide to the Galaxy'' (a trilogy in 4 > parts) --- however it does have a basis in the standard model of physics --- > a paper in Phys.Rev. of the early 1970s described the unification of the > Electro-Weak and Strong nuclear forces --- the arbitrary constant (of nearly) > 42 appears in the calculations. I forget the original paper but if you get > hold of Frank Close ``The Cosmic Onion'' a graph reproduces the result. I met > Douglas Adams once at a book signing and asked him how he got hold of the > Phys.Rev. paper so early. Technically he should have written that ``42 is the > answer to life, the universe and everything except for gravity and a few > other arbitrary constants'' In the Japanese culture the number 42 has a very special meaning. I realized that while discussing cultural differences with a Japanese. Pronouncing 42 sounds like "death" or "to die". No hotel in Japan has a room 42. After knowing that it is hard to think that Doug Adams was not aware of that meaning. Best, Tinu From bbrown at botspiritcompany.com Fri Feb 1 17:05:07 2008 From: bbrown at botspiritcompany.com (bbrown) Date: Fri Feb 1 17:04:24 2008 Subject: [Haskell-cafe] Issues with hsql-sqllite build; errors from the hackage download Message-ID: <20080201220114.M74223@www.botspiritcompany.com> There seems to be an issue with the hsql-sqlite3. Anyone have a fix. Should I use what is from darcs? Index of /packages/archive/hsql-sqlite3/1.7/logs/failure The Glorious Glasgow Haskell Compilation System, version 6.8.1 $ runhaskell Setup.lhs configure Setup.lhs:7:33: Module `Distribution.Simple.Utils' does not export `rawSystemVerbose' -- Berlin Brown [berlin dot brown at gmail dot com] http://botspiritcompany.com/botlist/? From lennart at augustsson.net Fri Feb 1 17:19:17 2008 From: lennart at augustsson.net (Lennart Augustsson) Date: Fri Feb 1 17:18:30 2008 Subject: [Haskell-cafe] A handy little consequence of the Cont monad In-Reply-To: <20080201214858.GF31711@cs.cmu.edu> References: <89ca3d1f0801312109k718f60a9maeef1c5e1025cc28@mail.gmail.com> <1201901226.5496.79.camel@derek-laptop> <20080201214858.GF31711@cs.cmu.edu> Message-ID: It's a matter of taste. I prefer the function composition in this case. It reads nicely as a pipeline. -- Lennart On Fri, Feb 1, 2008 at 9:48 PM, Dan Licata wrote: > Not to start a flame war or religious debate, but I don't think that > eta-expansions should be considered bad style. I realize that > composition-style is good for certain types of reasoning, but fully > eta-expanded code has an important legibility advantage: you can tell > the shape of its type just by looking at it! Personally, I'd rather > read the original version. > > -Dan > > On Feb01, Derek Elkins wrote: > > On Fri, 2008-02-01 at 00:09 -0500, Cale Gibbard wrote: > > > Hello, > > > > > > Today on #haskell, resiak was asking about a clean way to write the > > > function which allocates an array of CStrings using withCString and > > > withArray0 to produce a new with* style function. I came up with the > > > following: > > > > > > nest :: [(r -> a) -> a] -> ([r] -> a) -> a > > > nest xs = runCont (sequence (map Cont xs)) > > > > This is what you write after all that time on #haskell? > > > > nest = runCont . sequence . map Cont > > > > _______________________________________________ > > Haskell-Cafe mailing list > > Haskell-Cafe@haskell.org > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080201/21ca5539/attachment.htm From derek.a.elkins at gmail.com Fri Feb 1 17:21:41 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Fri Feb 1 17:21:05 2008 Subject: [Haskell-cafe] A handy little consequence of the Cont monad In-Reply-To: <20080201214858.GF31711@cs.cmu.edu> References: <89ca3d1f0801312109k718f60a9maeef1c5e1025cc28@mail.gmail.com> <1201901226.5496.79.camel@derek-laptop> <20080201214858.GF31711@cs.cmu.edu> Message-ID: <1201904502.5496.81.camel@derek-laptop> On Fri, 2008-02-01 at 16:48 -0500, Dan Licata wrote: > Not to start a flame war or religious debate, but I don't think that > eta-expansions should be considered bad style. I realize that > composition-style is good for certain types of reasoning, but fully > eta-expanded code has an important legibility advantage: you can tell > the shape of its type just by looking at it! Personally, I'd rather > read the original version. Clearly you don't hang out on #haskell enough and have missed the humor. From conor at strictlypositive.org Fri Feb 1 17:29:02 2008 From: conor at strictlypositive.org (Conor McBride) Date: Fri Feb 1 17:28:00 2008 Subject: [Haskell-cafe] A handy little consequence of the Cont monad In-Reply-To: References: <89ca3d1f0801312109k718f60a9maeef1c5e1025cc28@mail.gmail.com> <1201901226.5496.79.camel@derek-laptop> <20080201214858.GF31711@cs.cmu.edu> Message-ID: Folks On 1 Feb 2008, at 22:19, Lennart Augustsson wrote: > It's a matter of taste. I prefer the function composition in this > case. > It reads nicely as a pipeline. > > -- Lennart > Dan L : > On Fri, Feb 1, 2008 at 9:48 PM, Dan Licata wrote: > Not to start a flame war or religious debate, but I don't think that > eta-expansions should be considered bad style. Cale: > > > nest :: [(r -> a) -> a] -> ([r] -> a) -> a > > > nest xs = runCont (sequence (map Cont xs)) > > Derek: > > This is what you write after all that time on #haskell? > > > > nest = runCont . sequence . map Cont Pardon my voodoo (apologies to libraries readers, but here we go again, slightly updated). With these useful general purpose goodies... > module Newtype where > import Data.Monoid > class Newtype p u | p -> u where > unpack :: p -> u > instance Newtype p u => Newtype (a -> p) (a -> u) where > unpack = (unpack .) > op :: Newtype p u => (u -> p) -> p -> u > op _ p = unpack p > wrap :: Newtype p u => (x -> y) ->(y -> p) -> x -> u > wrap pack f = unpack . f . pack > ala :: Newtype p' u' => (u -> p) -> > ((a -> p) -> b -> p') -> > (a -> u) -> b -> u' > ala pack hitWith = wrap (pack .) hitWith ...and the suitable Newtype instance for Cont, I get to write... nest = ala Cont traverse id ..separating the newtype encoding from what's really going on, fusing the map with the sequence, and generalizing to any old Traversable structure. Third-order: it's a whole other order. Conor From jerzy.karczmarczuk at info.unicaen.fr Fri Feb 1 17:43:33 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Fri Feb 1 17:42:46 2008 Subject: [Haskell-cafe] Re: Who started 42, and when? In-Reply-To: <871w7wacx3.fsf@tnoo.net> References: <6f9f8f4a0802010557g56c7457dx4227131fe63689a6@mail.gmail.com> <6f9f8f4a0802010603h4d091167p10e21a64c820b791@mail.gmail.com> <40190312-5D60-48CE-A04D-6894DC984E57@kingston.ac.uk> <871w7wacx3.fsf@tnoo.net> Message-ID: Martin L?thi: > In the Japanese culture the number 42 has a very special meaning. I > realized that while discussing cultural differences with a Japanese. > Pronouncing 42 sounds like "death" or "to die". No hotel in Japan has a > room 42. > > After knowing that it is hard to think that Doug Adams was not aware of > that meaning. Phil Molyneux: > ... it does have a basis in the standard model of physics --- > a paper in Phys.Rev. of the early 1970s described the unification of the > Electro-Weak and Strong nuclear forces --- the arbitrary constant > (of nearly) 42 appears in the calculations. I forget the original paper > but if you get hold of Frank Close ``The Cosmic Onion'' a graph > reproduces the result. I met Douglas Adams once at a book signing and > asked him how he got hold of the Phys.Rev. paper so early. Technically he > should have written that ``42 is the answer to life, the universe and > everything except for gravity and a few other arbitrary constants'' Bother...! You will discover the third (or the sixth?) moment of the Riemann zeta function which has this 42 in it, and without doubt, you will find something in Talmud and the Pyramides. And the mass of the Galaxy which is 3*10^42. And it takes light 10^(-42) sec. to cross the diameter of a proton, although if I were light, I wouldn'd do such silly thing. Fortunately I am heavy. And at least one of YOU is 42 years old, and I was once. (Yes, the number 1 which is even more magical). Perhaps before claiming before you know really something, because Adams told you so personally, you have a look here. http://groups.google.com/group/alt.fan.douglas-adams/msg/d1064f7b27808692?dm ode=source&hl=en ... And if you run a non-optimized Haskell program which computes the Fibonacci of 42, then you have to wait so long, that you must build a special Supercomputer for it. It has, BTW. been built, and it is called the "haskell-cafe mailing list". Jerzy Karczmarczuk From dons at galois.com Fri Feb 1 17:51:34 2008 From: dons at galois.com (Don Stewart) Date: Fri Feb 1 17:50:57 2008 Subject: [Haskell-cafe] A handy little consequence of the Cont monad In-Reply-To: <1201904502.5496.81.camel@derek-laptop> References: <89ca3d1f0801312109k718f60a9maeef1c5e1025cc28@mail.gmail.com> <1201901226.5496.79.camel@derek-laptop> <20080201214858.GF31711@cs.cmu.edu> <1201904502.5496.81.camel@derek-laptop> Message-ID: <20080201225134.GH4029@scytale.galois.com> derek.a.elkins: > On Fri, 2008-02-01 at 16:48 -0500, Dan Licata wrote: > > Not to start a flame war or religious debate, but I don't think that > > eta-expansions should be considered bad style. I realize that > > composition-style is good for certain types of reasoning, but fully > > eta-expanded code has an important legibility advantage: you can tell > > the shape of its type just by looking at it! Personally, I'd rather > > read the original version. > > Clearly you don't hang out on #haskell enough and have missed the humor. For those not following, the last thing one does before comitting any Haskell code, once you've been on #haskell, is to feed it to lambdabot for "improvement" :) dons> @pl \f g (a,b) -> (f a, g b) lambdabot> flip flip snd . (ap .) . flip flip fst . ((.) .) . flip . (((.) . (,)) .) Ah, much better. We have a strange culture. -- Don From simonpj at microsoft.com Fri Feb 1 20:12:35 2008 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Fri Feb 1 20:09:29 2008 Subject: [Haskell-cafe] Haskell maximum stack depth In-Reply-To: <479F7BC9.9030406@iee.org> References: <404396ef0801280728s36dea93fn27733fc400f4e401@mail.gmail.com> <479E1415.2000908@gotadsl.co.uk> <404396ef0801281007y6a8acd90p434e6604bed15ce9@mail.gmail.com> <1201563268.5444.14.camel@derek-laptop> <479EE139.5090706@iee.org> <404396ef0801290128x2518d723g69be9e3c9bf7c0c4@mail.gmail.com> <479F7BC9.9030406@iee.org> Message-ID: <638ABD0A29C8884A91BC5FB5C349B1C318325D6F0F@EA-EXMSG-C334.europe.corp.microsoft.com> | Yes, using lots of stack is clearly bad with ghc, but this is a ghc | "bug". In fact the only reason these programs do use lots of stack | (vs. heap) is just a peculiarity of ghc rts implementation, so it | really should be ghc that fixes the problem, or at least admits | responsibility :-) I don't think there's anything fundamental here. GHC allocates the stack in the heap, and it can grow as big as you like. The size limit is simply to catch infinite recursion with a more helpful message than "heap overflow". I think. There is one peculiarity though: I don't think we ever shrink the stack, so once it gets big it stays big. This could be fixed, though. In short, feel free to set a very big max-stack size. If you are going to grow a stack of size N or a heap-allocated list of size N, the stack version will probably be more efficient -- with the caveat about deallocation that I mentioned. Simon From isaacdupree at charter.net Fri Feb 1 22:10:11 2008 From: isaacdupree at charter.net (Isaac Dupree) Date: Fri Feb 1 22:09:02 2008 Subject: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?) In-Reply-To: <200802012205.16432.g9ks157k@acme.softbase.org> References: <6a7c66fc0801310302p6bdee4adm6cf6a2778772ecbf@mail.gmail.com> <200801312335.21615.g9ks157k@acme.softbase.org> <47A29BDC.9010709@charter.net> <200802012205.16432.g9ks157k@acme.softbase.org> Message-ID: <47A3DF13.2080106@charter.net> Wolfgang Jeltsch wrote: > Am Freitag, 1. Februar 2008 05:11 schrieben Sie: >> Wolfgang Jeltsch wrote: >>> Well, the representation (D1,D2,D9) might be considered more readable. >>> It has the disadvantage of a fixed maximum size for the numbers. Which >>> takes me to a point I had already considered some time ago: Wouldn?t it >>> be good if we had just a type >>> >>> data Pair val1 val2 = Pair val1 val2 >>> >>> and if then (val1,val2,?,valn) would just be syntactic sugar for this: >>> >>> val1 `Pair` (val2 `Pair` (?(valn `Pair` ())?)) >> I've thought of that too.. besides the asymmetry, the presence of >> _|_/seq makes them actually not equivalent though, unfortunately >> >> ~Isaac > > With Ryan?s proposal (using strictness annotations) the new representation > should be equivalent to the old one. Or am I missing something? adding the strictness annotation seems to make them equivalent, yes I agree (I hadn't seen that post when I wrote that reply) ~Isaac From derek.a.elkins at gmail.com Fri Feb 1 23:28:28 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Fri Feb 1 23:27:45 2008 Subject: [Haskell-cafe] parsec3 pre-release Message-ID: <1201926508.5496.103.camel@derek-laptop> I'm currently getting Paolo Martini's Google Summer of Code project, an updated version of Parsec, into a releasable state, and I will be maintaining it for at least a while. Paolo's major additions are: * The Parser monad has been generalized into a Parser monad transformer * The parsers have been generalized to work over a stream of any type, in particular, with bytestrings. I have made a few minor additions as well: * There is Haddock documentation for almost all functions * The Parser monad now has Applicative/Alternative instances Currently, I am looking for people to give it a go reporting any bugs in the library or documentation, troubles building it, or changes/features they would like. I'm also interested in performance information. Most old Parsec code should be relatively easy but not trivial to port. There is a darcs repository on code.haskell.org. If nothing comes up, I'll put a package on Hackage in about a week or so. To get the code: darcs get http://code.haskell.org/ To build it, the standard cabal commands should work: http://haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package Alternatively, you can use the cabal-install application: http://hackage.haskell.org/trac/hackage/wiki/CabalInstall The documentation can be generated also via the normal cabal routine, or via cabal-install. From derek.a.elkins at gmail.com Fri Feb 1 23:53:59 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Fri Feb 1 23:53:16 2008 Subject: [Haskell-cafe] parsec3 pre-release [important note] Message-ID: <1201928039.5496.107.camel@derek-laptop> I forgot to mention that the Text.Parsec modules should be preferred to the Text.ParserCombinators.Parsec modules as the Haddock documentation reveals. From derek.a.elkins at gmail.com Sat Feb 2 00:15:42 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Sat Feb 2 00:15:00 2008 Subject: [Haskell-cafe] parsec3 pre-release [attempt 2] Message-ID: <1201929342.5496.112.camel@derek-laptop> [Now with 100% more correct darcs get URLs.] I'm currently getting Paolo Martini's Google Summer of Code project, an updated version of Parsec, into a releasable state, and I will be maintaining it for at least a while. Paolo's major additions are: * The Parser monad has been generalized into a Parser monad transformer * The parsers have been generalized to work over a stream of any type, in particular, with bytestrings. I have made a few minor additions as well: * There is Haddock documentation for almost all functions * The Parser monad now has Applicative/Alternative instances Currently, I am looking for people to give it a go reporting any bugs in the library or documentation, troubles building it, or changes/features they would like. I'm also interested in performance information. Most old Parsec code should be relatively easy but not trivial to port. There is a darcs repository on code.haskell.org. If nothing comes up, I'll put a package on Hackage in about a week or so. To get the code: darcs get http://code.haskell.org/parsec3 To build it, the standard cabal commands should work: http://haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package Alternatively, you can use the cabal-install application: http://hackage.haskell.org/trac/hackage/wiki/CabalInstall The documentation can be generated also via the normal cabal routine, or via cabal-install. The Text.Parsec modules should be preferred to the Text.ParserCombinators.Parsec modules. From lpillay at webafrica.org.za Sat Feb 2 01:30:02 2008 From: lpillay at webafrica.org.za (Logesh Pillay) Date: Sat Feb 2 01:30:21 2008 Subject: [Haskell-cafe] newbie q about types Message-ID: <47A40DEA.2020107@webafrica.org.za> I have a list. Each component is a list with 2 whole numbers. I want to multiply the second number by the log of the first eg tail ([519432,525806]) * log (head [519432,525806]). I get the ffg error message: No instance for (Floating [t]) arising from a use of `log' at :1:25-50 Possible fix: add an instance declaration for (Floating [t]) In the second argument of `(*)', namely `log (head [519432, 525806])' In the expression: tail ([519432, 525806]) * log (head [519432, 525806]) In the definition of `it': it = tail ([519432, 525806]) * log (head [519432, 525806]) I've tried the only type signature I know "fromIntegral" but it does not help. How to fix? Thanks Logesh From jonathanccast at fastmail.fm Sat Feb 2 01:37:17 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sat Feb 2 01:36:36 2008 Subject: [Haskell-cafe] newbie q about types In-Reply-To: <47A40DEA.2020107@webafrica.org.za> References: <47A40DEA.2020107@webafrica.org.za> Message-ID: <2B638A2D-3398-4A25-AE1A-87E7A3D8A4E0@fastmail.fm> On 1 Feb 2008, at 10:30 PM, Logesh Pillay wrote: > I have a list. Each component is a list with 2 whole numbers. First off, why? In Haskell (unlike dynamically typed languages like Python or Perl), if you know you always have two elements, you want a pair (519432,525806), not a list [519432,525806]. > I want to multiply the second number by the log of the first > eg > tail ([519432,525806]) * log (head [519432,525806]). You mean [519432,525806] !! 1 * log ([519432,525806 !! 0) or fst (519432,525806) * log (snd (519432,525806) or (best of all) case (519432, 525806) of (x, y) -> x * log y or (if you must have a list) case [519432, 525806] of [x, y] -> x * log y > I get the ffg error message: > > No instance for (Floating [t]) This is because tail :: [t] -> [t] It doesn't give you a single element; it gives you the whole list! jcc From lrpalmer at gmail.com Sat Feb 2 01:41:03 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Sat Feb 2 01:40:15 2008 Subject: [Haskell-cafe] newbie q about types In-Reply-To: <47A40DEA.2020107@webafrica.org.za> References: <47A40DEA.2020107@webafrica.org.za> Message-ID: <7ca3f0160802012241y2ba3028ftdca55713dd0dfa93@mail.gmail.com> Look at the type of tail: tail :: [a] -> [a] That is, tail is the list of all elements *except* the head. You want "last". (Barring style considerations. Usually in a situation like this you would use a list of tuples rather than a list of lists, since then you know at compile time that you have exactly two numbers in each element of the list). Luke On Feb 2, 2008 6:30 AM, Logesh Pillay wrote: > I have a list. Each component is a list with 2 whole numbers. I want > to multiply the second number by the log of the first > eg > tail ([519432,525806]) * log (head [519432,525806]). > > I get the ffg error message: > > No instance for (Floating [t]) > arising from a use of `log' at :1:25-50 > Possible fix: add an instance declaration for (Floating [t]) > In the second argument of `(*)', namely > `log (head [519432, 525806])' > In the expression: > tail ([519432, 525806]) * log (head [519432, 525806]) > In the definition of `it': > it = tail ([519432, 525806]) * log (head [519432, 525806]) > > > I've tried the only type signature I know "fromIntegral" but it does not > help. > > How to fix? > > Thanks > Logesh > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From bulat.ziganshin at gmail.com Fri Feb 1 18:56:25 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sat Feb 2 02:20:31 2008 Subject: [Haskell-cafe] A handy little consequence of the Cont monad In-Reply-To: References: <89ca3d1f0801312109k718f60a9maeef1c5e1025cc28@mail.gmail.com> <1201901226.5496.79.camel@derek-laptop> <20080201214858.GF31711@cs.cmu.edu> Message-ID: <1493971874.20080202025625@gmail.com> Hello Conor, Saturday, February 2, 2008, 1:29:02 AM, you wrote: > nest = ala Cont traverse id > Third-order: it's a whole other order. oh! i remember faces of my friends when i showed them something like "sortOn snd . zip [0..]". probably i have the same face now :))) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From jeff1.61803 at gmail.com Sat Feb 2 05:32:44 2008 From: jeff1.61803 at gmail.com (=?ISO-8859-7?Q?Jeff_=F6?=) Date: Sat Feb 2 05:31:56 2008 Subject: [Haskell-cafe] Mutable arrays Message-ID: <7665bf90802020232w3ede6fb4ibf12d9d1d99fff61@mail.gmail.com> Hello, I'm trying to write code that will take a mutable 2D array and normalize it by dividing all elements by the largest element. I managed to write code to do this, but it seems overly complex. I could write something much simpler in Clean or C++. Most likely, my code is complex because I don't have any experience with mutable arrays in Haskell. I couldn't find any tutorials on the Internet. I'd be grateful for suggestions on simplifying the following code. Thanks. {-# OPTIONS_GHC -fglasgow-exts -fbreak-on-exception #-} -- normalize_ary This takes a mutable array. Determines the largest -- element in the array (max_elem) and then divides every element by -- max_elem. normalize_ary :: (Num t1, Num t, Ix t, Ix t1, MArray a e t2, Ord e, Fractional e, Enum t, Enum t1) => a (t, t1) e -> t2 () normalize_ary ary = do -- The following two commented out lines of code show my first -- attempt at determining a value for max_elem. However, this -- produces a stack overflow. -- elem_ary <- getElems ary -- let max_elem = foldl1 max elem_ary max_elem <- calc_max_2d_elem ary max_elem `seq` map_in_place_2d_arr (\x -> x / max_elem) ary map_in_place_2d_arr :: (MArray a e t, Enum t2, Enum t1, Ix t1, Ix t2) => (e -> e) -> a (t1, t2) e -> t () map_in_place_2d_arr fn arr = ret where ret = do ((i1,j1),(i2,j2)) <- getBounds arr ( mapM_ (\i -> do v <- readArray arr i writeArray arr i (fn v) ) [(i,j) | i <- [i1..i2], j <- [j1..j2]]) calc_max_2d_elem :: (Ord t, MArray a t t1, Ix t2, Ix t3, Num t3, Num t2) => a (t3, t2) t -> t1 t calc_max_2d_elem arr = do m <- readArray arr (0,0) (_,(i_max, j_max)) <- getBounds arr let calc_max_loop arr m (i,j) | j == j_max = return m | otherwise = do e <- readArray arr (i,j) let m2 = max e m m2 `seq` calc_max_loop arr m2 nxt_idx where nxt_idx | i == i_max - 1 = (0,j+1) | otherwise = (i+1,j) calc_max_loop arr m (0,0) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080202/15382352/attachment.htm From lrpalmer at gmail.com Sat Feb 2 06:26:12 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Sat Feb 2 06:25:24 2008 Subject: [Haskell-cafe] Mutable arrays In-Reply-To: <7665bf90802020232w3ede6fb4ibf12d9d1d99fff61@mail.gmail.com> References: <7665bf90802020232w3ede6fb4ibf12d9d1d99fff61@mail.gmail.com> Message-ID: <7ca3f0160802020326p62bff99eg2b3c8abd0b033857@mail.gmail.com> I prerequest your forgiveness if I sound patronizing, I'm just writing everything that comes to mind. 2008/2/2 Jeff ? : > {-# OPTIONS_GHC -fglasgow-exts -fbreak-on-exception #-} > > -- normalize_ary This takes a mutable array. Determines the largest > -- element in the array (max_elem) and then divides every element by > -- max_elem. > normalize_ary :: (Num t1, > Num t, > Ix t, > Ix t1, > MArray a e t2, > Ord e, > Fractional e, > Enum t, > Enum t1) => > a (t, t1) e -> t2 () Yagh! Look at that type signature. That looks like it came from ghci. That type should raise a few alarms, such as the Num t, Num t1. Why should the indices be numbers? That indicates that your implementation is not as general as it should be, so maybe try another method. (Really it's calc_max_2d_elem which is losing that generality). I usually write my type signatures first, and then let that guide my implementation. But you will find differing valid opinions on this list on that issue. Anyway, without further ado, into the guts we go. > normalize_ary ary = > do > -- The following two commented out lines of code show my first > -- attempt at determining a value for max_elem. However, this > -- produces a stack overflow. > > -- elem_ary <- getElems ary > -- let max_elem = foldl1 max elem_ary Hmm, how big is the array? If it's pretty big, that's understandable. Frankly, it's because foldl sucks: I have never seen a reason to use it. You should be using the strict variant foldl' here. (I don't think there is a foldl1'). And that will get rid of your big function calc_max_2d_elem. > > max_elem <- calc_max_2d_elem ary > max_elem `seq` map_in_place_2d_arr (\x -> x / max_elem) ary I don't think that max_elem `seq` is doing anything useful here (but I could be missing something subtle). Oh and a really low level thing which may or may not make a difference: floating point division is expensive. You'd be better off precalculating 1 / max_elem and then multiplying by that instead. > map_in_place_2d_arr :: (MArray a e t, Enum t2, Enum t1, Ix t1, Ix t2) => > (e -> e) -> a (t1, t2) e -> t () Another conspicuous type signature. Enum t2, Enum t1 is the red flag here. It's because you're using [i1..i2] instead of range (i1,i2) from Data.Ix. > map_in_place_2d_arr fn arr = ret > where > ret = do ((i1,j1),(i2,j2)) <- getBounds arr > ( mapM_ (\i -> do v <- readArray arr i > writeArray arr i (fn v) ) > [(i,j) | i <- [i1..i2], j <- [j1..j2]]) This looks pretty good modulo the [i1..i2] I mentioned above. For this kind of stuff I prefer to use forM_, as it is a more imperative-looking construct for imperative-looking code (then you can lose the parentheses around (\i -> ...))... > calc_max_2d_elem :: (Ord t, MArray a t t1, Ix t2, Ix t3, Num t3, Num t2) => > a (t3, t2) t -> t1 t > calc_max_2d_elem arr = > do m <- readArray arr (0,0) > (_,(i_max, j_max)) <- getBounds arr > let calc_max_loop arr m (i,j) > | j == j_max = return m > | otherwise = do e <- readArray arr (i,j) > let m2 = max e m > m2 `seq` calc_max_loop arr m2 nxt_idx > where nxt_idx | i == i_max - 1 = (0,j+1) > | otherwise = (i+1,j) > calc_max_loop arr m (0,0) Hopefully we have done away with this thing given the foldl' thing. There are a lot of implicit assumptions hiding in this code, such as indices being zero-based integers. Writing your type signature first would have caught those assumptions, since you wouldn't have had (Num t3, Num t2) ;-). Luke From alfonso.acosta at gmail.com Sat Feb 2 07:46:10 2008 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Sat Feb 2 07:45:22 2008 Subject: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?) In-Reply-To: <200802012233.28126.g9ks157k@acme.softbase.org> References: <6a7c66fc0801310302p6bdee4adm6cf6a2778772ecbf@mail.gmail.com> <6a7c66fc0802010400g71094d4fy66cc40483de699dc@mail.gmail.com> <6a7c66fc0802010409i635c47e2xe7c34e69007dd436@mail.gmail.com> <200802012233.28126.g9ks157k@acme.softbase.org> Message-ID: <6a7c66fc0802020446v6daaf9c2i25e2713ec268101f@mail.gmail.com> On Feb 1, 2008 10:33 PM, Wolfgang Jeltsch wrote: > > Actually it would maybe be better to create common high-level > > interface that could include unary, binary and decimal arithmetic so > > that the library could be easily reused in other projects (people like > > Bjorn, seem to be using the unary implementation). I don't know if it > > would be feasible though. > > I'd say, let's start with the decimal thing. We can extend our package later > if there's a need to do this, can't we? OK, let's do it like that. From overdrigzed at gmail.com Sat Feb 2 07:57:47 2008 From: overdrigzed at gmail.com (Rodrigo Queiro) Date: Sat Feb 2 07:56:58 2008 Subject: [Haskell-cafe] Mutable arrays In-Reply-To: <7665bf90802020232w3ede6fb4ibf12d9d1d99fff61@mail.gmail.com> References: <7665bf90802020232w3ede6fb4ibf12d9d1d99fff61@mail.gmail.com> Message-ID: <2eb8984a0802020457s68850ffg5d8dc8432a2aa3c4@mail.gmail.com> This is my attempt at some nicer code: maximum' (x:xs) = foldl' max x xs maximum' _ = undefined modifyArray :: (MArray a e m, Ix i) => (e -> e) -> a i e -> m () modifyArray fn arr = do bounds <- getBounds arr forM_ (range bounds) (modifyElement fn arr) modifyElement :: (MArray a e m, Ix i) => (e -> e) -> a i e -> i -> m () modifyElement fn arr i = do x <- readArray arr i writeArray arr i (fn x) normalizeArray :: (MArray a e m, Ix i, Fractional e, Ord e) => a i e -> m () normalizeArray arr = do arr_elems <- getElems arr let max_elem = maximum' arr_elems modifyArray (/max_elem) arr On 02/02/2008, Jeff ? wrote: > Hello, > > I'm trying to write code that will take a mutable 2D array and normalize it > by dividing all elements by the largest element. > > I managed to write code to do this, but it seems overly complex. I could > write something much simpler in Clean or C++. Most likely, my code is > complex because I don't have any experience with mutable arrays in Haskell. > I couldn't find any tutorials on the Internet. I'd be grateful for > suggestions on simplifying the following code. Thanks. > > > {-# OPTIONS_GHC -fglasgow-exts -fbreak-on-exception #-} > > -- normalize_ary This takes a mutable array. Determines the largest > -- element in the array (max_elem) and then divides every element by > -- max_elem. > normalize_ary :: (Num t1, > Num t, > Ix t, > Ix t1, > MArray a e t2, > Ord e, > Fractional e, > Enum t, > Enum t1) => > a (t, t1) e -> t2 () > normalize_ary ary = > do > -- The following two commented out lines of code show my first > -- attempt at determining a value for max_elem. However, this > -- produces a stack overflow. > > -- elem_ary <- getElems ary > -- let max_elem = foldl1 max elem_ary > > max_elem <- calc_max_2d_elem ary > max_elem `seq` map_in_place_2d_arr (\x -> x / max_elem) ary > > > map_in_place_2d_arr :: (MArray a e t, Enum t2, Enum t1, Ix t1, Ix t2) => > (e -> e) -> a (t1, t2) e -> t () > map_in_place_2d_arr fn arr = ret > where > ret = do ((i1,j1),(i2,j2)) <- getBounds arr > ( mapM_ (\i -> do v <- readArray arr i > writeArray arr i (fn v) > ) > [(i,j) | i <- [i1..i2], j <- [j1..j2]]) > > > calc_max_2d_elem :: (Ord t, MArray a t t1, Ix t2, Ix t3, Num t3, Num t2) => > a (t3, t2) t -> t1 t > calc_max_2d_elem arr = > do m <- readArray arr (0,0) > (_,(i_max, j_max)) <- getBounds arr > let calc_max_loop arr m (i,j) > | j == j_max = return m > | otherwise = do e <- readArray arr (i,j) > let m2 = max e m > m2 `seq` calc_max_loop > arr m2 nxt_idx > where nxt_idx | i == i_max - 1 = (0,j+1) > | otherwise = (i+1,j) > calc_max_loop arr m (0,0) > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080202/0575fc32/attachment.htm From overdrigzed at gmail.com Sat Feb 2 08:11:58 2008 From: overdrigzed at gmail.com (Rodrigo Queiro) Date: Sat Feb 2 08:11:09 2008 Subject: [Haskell-cafe] Mutable arrays In-Reply-To: <2eb8984a0802020457s68850ffg5d8dc8432a2aa3c4@mail.gmail.com> References: <7665bf90802020232w3ede6fb4ibf12d9d1d99fff61@mail.gmail.com> <2eb8984a0802020457s68850ffg5d8dc8432a2aa3c4@mail.gmail.com> Message-ID: <2eb8984a0802020511y3215cce2m698d2af2baa562d8@mail.gmail.com> Sorry, I was lazy. New maximum': maximum' = foldl1' max On 02/02/2008, Rodrigo Queiro wrote: > > This is my attempt at some nicer code: > > maximum' (x:xs) = foldl' max x xs > maximum' _ = undefined > > modifyArray :: (MArray a e m, Ix i) => (e -> e) -> a i e -> m () > modifyArray fn arr = do > bounds <- getBounds arr > forM_ (range bounds) (modifyElement fn arr) > > modifyElement :: (MArray a e m, Ix i) => (e -> e) -> a i e -> i -> m () > modifyElement fn arr i = do > x <- readArray arr i > writeArray arr i (fn x) > > normalizeArray :: (MArray a e m, Ix i, Fractional e, Ord e) => a i e -> m > () > normalizeArray arr = do > arr_elems <- getElems arr > let max_elem = maximum' arr_elems > modifyArray (/max_elem) arr > > On 02/02/2008, Jeff ? wrote: > > Hello, > > > > I'm trying to write code that will take a mutable 2D array and normalize > it > > by dividing all elements by the largest element. > > > > I managed to write code to do this, but it seems overly complex. I > could > > write something much simpler in Clean or C++. Most likely, my code is > > complex because I don't have any experience with mutable arrays in > Haskell. > > I couldn't find any tutorials on the Internet. I'd be grateful for > > suggestions on simplifying the following code. Thanks. > > > > > > {-# OPTIONS_GHC -fglasgow-exts -fbreak-on-exception #-} > > > > -- normalize_ary This takes a mutable array. Determines the largest > > -- element in the array (max_elem) and then divides every element by > > -- max_elem. > > normalize_ary :: (Num t1, > > Num t, > > Ix t, > > Ix t1, > > MArray a e t2, > > Ord e, > > Fractional e, > > Enum t, > > Enum t1) => > > a (t, t1) e -> t2 () > > normalize_ary ary = > > do > > -- The following two commented out lines of code show my first > > -- attempt at determining a value for max_elem. However, this > > -- produces a stack overflow. > > > > -- elem_ary <- getElems ary > > -- let max_elem = foldl1 max elem_ary > > > > max_elem <- calc_max_2d_elem ary > > max_elem `seq` map_in_place_2d_arr (\x -> x / max_elem) ary > > > > > > map_in_place_2d_arr :: (MArray a e t, Enum t2, Enum t1, Ix t1, Ix t2) > => > > (e -> e) -> a (t1, t2) e -> t () > > map_in_place_2d_arr fn arr = ret > > where > > ret = do ((i1,j1),(i2,j2)) <- getBounds arr > > ( mapM_ (\i -> do v <- readArray arr i > > writeArray arr i (fn v) > > ) > > [(i,j) | i <- [i1..i2], j <- [j1..j2]]) > > > > > > calc_max_2d_elem :: (Ord t, MArray a t t1, Ix t2, Ix t3, Num t3, Num t2) > => > > a (t3, t2) t -> t1 t > > calc_max_2d_elem arr = > > do m <- readArray arr (0,0) > > (_,(i_max, j_max)) <- getBounds arr > > let calc_max_loop arr m (i,j) > > | j == j_max = return m > > | otherwise = do e <- readArray arr (i,j) > > let m2 = max e m > > m2 `seq` calc_max_loop > > arr m2 nxt_idx > > where nxt_idx | i == i_max - 1 = (0,j+1) > > | otherwise = (i+1,j) > > calc_max_loop arr m (0,0) > > > > > > _______________________________________________ > > Haskell-Cafe mailing list > > Haskell-Cafe@haskell.org > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080202/657476c9/attachment.htm From alfonso.acosta at gmail.com Sat Feb 2 08:54:59 2008 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Sat Feb 2 08:54:10 2008 Subject: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?) In-Reply-To: <200802012232.16922.g9ks157k@acme.softbase.org> References: <6a7c66fc0801310302p6bdee4adm6cf6a2778772ecbf@mail.gmail.com> <200801312335.21615.g9ks157k@acme.softbase.org> <6a7c66fc0802010400g71094d4fy66cc40483de699dc@mail.gmail.com> <200802012232.16922.g9ks157k@acme.softbase.org> Message-ID: <6a7c66fc0802020554i5e96eb84n296e2df8bfec9f46@mail.gmail.com> On Feb 1, 2008 10:32 PM, Wolfgang Jeltsch wrote: > Am Freitag, 1. Februar 2008 13:00 schrieb Alfonso Acosta: > > On Jan 31, 2008 11:35 PM, Wolfgang Jeltsch > > > This is essentially what I had in mind. While Oleg's implementation > > > needs a "thrusted core", the GADT solution doesn't. > > > > True. However using GADTs doesn't allow to internally make use of > > Arrays, which (tell me if I'm wrong) are likely to be faster than the > > naive GADT implementation. > > It depends. My first GADT implementation is equivalent to the [] type and > often [] is better than arrays. For example, if you read the contents of a > file and process it with maps, filters, etc., [] is likely to give you > constant space usage which arrays don't. If you want to lookup elements by > index, then arrays are better, of course. For my purpose, it would be fine > to use a []-like implementation, I think. For mine it would be fine too. Let's implement our needs and then maybe extend it if someone rants about it. > > To make it friendlier for the end user I thought about defining > > aliases for lets say the first 10000 numbers using Template Haskell. > > That could even make error reports friendlier (not sure to what point > > though). What do you think? > > I have no clear opinion about that at the moment. Maybe it's okay to use the > representation directly. This way, we don't introduce a dependeny on the > Template Haskell language extension (which is only supported by GHC), and the > actual representation will occur in error messages anyway whenever the > message shows a computed number. Well, my EDSL already makes extensive use of TH. So, being selfish, it wouldn't be a problem for me (or any other GHC user) and I think it would make the library much more usable. Just compare f :: List (() :- D1 :- D0 :- D0 :- 1000) Int -> List (() :- D1 :- D0 :- D0 :- D0) Int with, let's say f :: List A1000 Int -> List A1000 Int Again, if someone complains about the TH dependency, the aliases could be generated by TH but saved statically in a module for each release. > > So, we'll be making two separate libraries then. We should think about > > names. > > > > What about FixedVector for the vector library and DecTypArith (maybe > > too long) or DecTypes for the type-level decimal arithmetic library? > > Alas, there is an inconsistency in naming packages already. Some prefer names > which are entirely lowercase, some prefer camel case. I prefer lowercase, > with hyphens separating parts of the name. And I also don't like unusual > abbreviations like "typ" (not much shorter than "type"). To mention > arithmetics is not so important. So maybe something > like "type-level-decimals"? > > Maybe it's better to put different type-level programming things into a single > package. Then we could name this package "type-level" or something similar. > We could start with our decimals. Other type-level things could be added > later. I already have some code about type-level booleans. It's not very > sensible to put these few lines into a separate package. It might be nice if > we had a general type-level programming package where I could put this code > into. Sounds sensible. However, I would rather prefer something like type-level-comp (from type level computations) or type-level-prog (from type level programming). Type level by itself doesn't describe the functionality of the package. > As for the name of the fixed-size list package, I have to say that I don't > like the term "vector" in this context. A vector is actually something with > addition and scalar multiplication defined on it. Maybe we should make also > this package's scope wider. What about something like "safe-data" or > similar? I think safe-data is a bit too general and might lead to confusion with other safe data packages (namely Mitchell's Safe library). Since the main particularity of the library is that safety properties are achieved via "emulating" dependent types I think that light-dependent-types (from lightweight dependent types), number-parameterized-data or simply parameterized-data (this is the name I like best) would be more appropiate. From alfonso.acosta at gmail.com Sat Feb 2 10:04:37 2008 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Sat Feb 2 10:03:47 2008 Subject: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?) In-Reply-To: <6a7c66fc0802020554i5e96eb84n296e2df8bfec9f46@mail.gmail.com> References: <6a7c66fc0801310302p6bdee4adm6cf6a2778772ecbf@mail.gmail.com> <200801312335.21615.g9ks157k@acme.softbase.org> <6a7c66fc0802010400g71094d4fy66cc40483de699dc@mail.gmail.com> <200802012232.16922.g9ks157k@acme.softbase.org> <6a7c66fc0802020554i5e96eb84n296e2df8bfec9f46@mail.gmail.com> Message-ID: <6a7c66fc0802020704j10ffd3a7m602d5d19e18602a9@mail.gmail.com> On Feb 2, 2008 2:54 PM, Alfonso Acosta wrote: > Just compare > > f :: List (() :- D1 :- D0 :- D0 :- 1000) Int -> List (() :- D1 :- D0 > :- D0 :- D0) Int I meant f :: List (() :- D1 :- D0 :- D0 :- D0) Int -> List (() :- D1 :- D0 :- D0 :- D0) Int sorry for the typo From duncan.coutts at worc.ox.ac.uk Sat Feb 2 10:08:16 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sat Feb 2 10:07:30 2008 Subject: [Haskell-cafe] Cabal, GHC, FFI and Visual Studio on Windows In-Reply-To: <47A30596.6080209@therning.org> References: <47A30596.6080209@therning.org> Message-ID: <1201964896.13130.132.camel@localhost> On Fri, 2008-02-01 at 11:42 +0000, Magnus Therning wrote: > Is it possible to get Cabal to use 'cl' (Microsoft's C/C++ compiler > shipped with Visual Studio Express)? The problem is to get GHC to use 'cl'. That's a longer term project that GHC HQ are interested in. There's something about it on the GHC dev wiki I think. Don't hold your breath. > I've found the Wiki page on using Visual Studio to create a DLL, then > convert it to a .a file so that GHC can consume it. I'd rather skip > using Visual Studio to build things and just ship a Cabalised package. You can create .dlls without using VS of course, if that's what you're trying to do. Duncan From duncan.coutts at worc.ox.ac.uk Sat Feb 2 10:16:06 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sat Feb 2 10:15:19 2008 Subject: [Haskell-cafe] Issues with hsql-sqllite build; errors from the hackage download In-Reply-To: <20080201220114.M74223@www.botspiritcompany.com> References: <20080201220114.M74223@www.botspiritcompany.com> Message-ID: <1201965366.13130.140.camel@localhost> On Fri, 2008-02-01 at 17:05 -0500, bbrown wrote: > There seems to be an issue with the hsql-sqlite3. Anyone have a fix. Should > I use what is from darcs? HSQL is currently unmaintained. Frederik Eaton was considering taking it over: http://www.nabble.com/HSQL-defunct--td14978532.html Gentoo has a fix: http://haskell.org/~gentoo/gentoo-haskell/dev-haskell/hsql-sqlite/hsql-sqlite-1.7.ebuild The code in src_unpack() is replacing the Setup.hs with a default copy and then adding 'extra-libraries: sqlite3' to the .cabal file. Pretty straightforward. This does assume that you have sqlite3 installed in the default global location. You may also like to consider alternatives like HDBC-sqlite3. Duncan From s.clover at gmail.com Sat Feb 2 12:07:07 2008 From: s.clover at gmail.com (Sterling Clover) Date: Sat Feb 2 12:06:23 2008 Subject: [Haskell-cafe] Issues with hsql-sqllite build; errors from the hackage download In-Reply-To: <1201965366.13130.140.camel@localhost> References: <20080201220114.M74223@www.botspiritcompany.com> <1201965366.13130.140.camel@localhost> Message-ID: <57BA8DFB-346D-422E-8F00-F2FE45F523B1@gmail.com> Just noticed, by the way, that haskelldb doesn't build correctly because it still hasn't updated the cabal for the base split. On the other hand, the development repo (which is 0.11 -- 0.10 is on hackage) builds fine. Are the maintainers planning to get an updated version on hackage? --S On Feb 2, 2008, at 10:16 AM, Duncan Coutts wrote: > > On Fri, 2008-02-01 at 17:05 -0500, bbrown wrote: >> There seems to be an issue with the hsql-sqlite3. Anyone have a >> fix. Should >> I use what is from darcs? > > HSQL is currently unmaintained. Frederik Eaton was considering > taking it > over: http://www.nabble.com/HSQL-defunct--td14978532.html > > Gentoo has a fix: > http://haskell.org/~gentoo/gentoo-haskell/dev-haskell/hsql-sqlite/ > hsql-sqlite-1.7.ebuild > The code in src_unpack() is replacing the Setup.hs with a default copy > and then adding 'extra-libraries: sqlite3' to the .cabal file. Pretty > straightforward. This does assume that you have sqlite3 installed > in the > default global location. > > You may also like to consider alternatives like HDBC-sqlite3. > > Duncan > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From chaddai.fouche at gmail.com Sat Feb 2 12:11:58 2008 From: chaddai.fouche at gmail.com (=?ISO-8859-1?Q?Chadda=EF_Fouch=E9?=) Date: Sat Feb 2 12:11:08 2008 Subject: [Haskell-cafe] Mutable arrays In-Reply-To: <2eb8984a0802020511y3215cce2m698d2af2baa562d8@mail.gmail.com> References: <7665bf90802020232w3ede6fb4ibf12d9d1d99fff61@mail.gmail.com> <2eb8984a0802020457s68850ffg5d8dc8432a2aa3c4@mail.gmail.com> <2eb8984a0802020511y3215cce2m698d2af2baa562d8@mail.gmail.com> Message-ID: 2008/2/2, Rodrigo Queiro : > Sorry, I was lazy. New maximum': > maximum' = foldl1' max Sorry but none of those propositions change the heart of the problem : the list of elements is totally produced before she can be consumed due to the strict monadic (IO or ST) nature of getElems. Thus you get an extraordinary waste of memory as well as resources... To address this I propose this function : foldl1MArray' :: (MArray a e m, Ix i) => (e -> e -> e) -> a i e -> m e foldl1MArray' f a = do (l,u) <- getBounds a firstElem <- readArray a l foldM (\a mb -> a `seq` mb >>= return . f a) firstElem (map (readArray a) (range (l,u))) With this, we can rewrite the original program using the excellent modifyArray from Rodrigo : normalizeArray :: (MArray a e m, Ix i, Fractional e, Ord e) => a i e -> m () normalizeArray arr = do max_elem <- foldl1MArray' max arr modifyArray (* (1/max_elem)) arr -- Jeda? From fmartini at gmail.com Sat Feb 2 12:15:27 2008 From: fmartini at gmail.com (Felix Martini) Date: Sat Feb 2 12:14:38 2008 Subject: [Haskell-cafe] Cabal, GHC, FFI and Visual Studio on Windows In-Reply-To: <1201964896.13130.132.camel@localhost> References: <47A30596.6080209@therning.org> <1201964896.13130.132.camel@localhost> Message-ID: <6c0416190802020915u7a3878dbh9c3fe30f8106a3f0@mail.gmail.com> Magnus Therning wrote: > Is it possible to get Cabal to use 'cl' (Microsoft's C/C++ compiler > shipped with Visual Studio Express)? Duncan Coutts wrote: > The problem is to get GHC to use 'cl'. That's a longer term project that > GHC HQ are interested in. There's something about it on the GHC dev wiki > I think. Don't hold your breath. When using the native code generator only foreign C code must be compiled with a C compiler. Presently Cabal passes C sources that are listed in the 'c-sources' field of a cabal file to GHC. It would be nice to have a Cabal field to specify the compiler for C sources, say 'c-sources-compiler: msvc'. The default would still be gcc, but with a Cabal flag the user would be able to change that to e.g. Sun's C compiler. From dbueno at gmail.com Sat Feb 2 12:26:18 2008 From: dbueno at gmail.com (Denis Bueno) Date: Sat Feb 2 12:25:29 2008 Subject: [Haskell-cafe] Re: HList error with hFoldr In-Reply-To: <20080128054545.D2E52A97B@Adric.metnet.fnmoc.navy.mil> References: <6dbd4d000801260803g7db6415co640dd78afcbe9f85@mail.gmail.com> <20080128054545.D2E52A97B@Adric.metnet.fnmoc.navy.mil> Message-ID: <6dbd4d000802020926y62715485kc0a5b0eaadb1caec@mail.gmail.com> On Jan 28, 2008 12:45 AM, wrote: > It seems strange that you need the types e and e' (perhaps this is a > quirk or a bug of GHC 6.8). With GHC 6.6, I have derived the following > > > instance (Floating f, MetricSpace e f, HFoldr ApplyDistSum Float l1 f, > HZip (HCons e l) (HCons e l) (HCons (e,e) l1)) > => MetricSpace (HCons e l) f where > c `dist` c' = sqrt $ hFoldr ApplyDistSum (0::Float) (hZip c c') > > which matches my intuitive understanding, and also sufficient to run > the given examples. This also works in GHC 6.8. Thanks! > When I wrote `I derived with GHC' I meant it literally. First I wrote > the instance without any constraints: > > instance () > => MetricSpace (HCons e l) f where > c `dist` c' = sqrt $ hFoldr ApplyDistSum (0::Float) (hZip c c') > > GHC of course complained about many missing constraints. I started > adding the constraints from the list of complaints, until GHC was > satisfied. This is basically a cut-and-paste job from the Emacs buffer > with GHC error messages to the buffer with the code. Wow. I will try this next time I post. Thanks very much. -- Denis From stefanor at cox.net Sat Feb 2 12:28:15 2008 From: stefanor at cox.net (Stefan O'Rear) Date: Sat Feb 2 12:27:26 2008 Subject: [Haskell-cafe] Mutable arrays In-Reply-To: <2eb8984a0802020457s68850ffg5d8dc8432a2aa3c4@mail.gmail.com> References: <7665bf90802020232w3ede6fb4ibf12d9d1d99fff61@mail.gmail.com> <2eb8984a0802020457s68850ffg5d8dc8432a2aa3c4@mail.gmail.com> Message-ID: <20080202172815.GA3596@localhost.localdomain> On Sat, Feb 02, 2008 at 12:57:47PM +0000, Rodrigo Queiro wrote: > This is my attempt at some nicer code: > > maximum' (x:xs) = foldl' max x xs > maximum' _ = undefined > > modifyArray :: (MArray a e m, Ix i) => (e -> e) -> a i e -> m () > modifyArray fn arr = do > bounds <- getBounds arr > forM_ (range bounds) (modifyElement fn arr) > > modifyElement :: (MArray a e m, Ix i) => (e -> e) -> a i e -> i -> m () > modifyElement fn arr i = do > x <- readArray arr i > writeArray arr i (fn x) > > normalizeArray :: (MArray a e m, Ix i, Fractional e, Ord e) => a i e -> m () > normalizeArray arr = do > arr_elems <- getElems arr > let max_elem = maximum' arr_elems > modifyArray (/max_elem) arr Note that by using getElems, you are throwing away most of the advantages of arrays, since it is strict (it has to be, since it's effectively an IO function and lazy IO is unsound wrt Haskell's normal semantics) and converts the whole thing into a list. If I just had this one bit of code to do, I'd use explicit loop: normalizeArray arr = do b <- getBounds arr ; m <- findMax b forM_ (range b) (edit m) where findMax (i:is) = findMax' is =<< readArray arr i findMax' (i:is) !v = findMax' is . max v =<< readArray arr i findMax' [] !v = return v edit mx i = writeArray arr i . (/mx) =<< readArray arr i With a little more, I'd probably set the scene with a few array-modifying combinators, inspired by Oleg's left-fold idea: -- yes, I'm passing four arguments to foldr. this is not a mistake. foldA fn ac arr = getBounds arr >>= \b -> foldr (\ i ct acc -> ct =<< fn i ac =<< readArray arr i) (\_ -> return ac) (range b) ac foldAp fn = foldA (\i a b -> return (fn a b)) maxA = foldAp max minBound mapA fn ar = foldA (\i _ v -> writeArray ar i (fn v)) () ar normalize arr = maxA arr >>= \ m -> mapA (/m) arr Stefan -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080202/847dfb44/attachment.bin From dbueno at gmail.com Sat Feb 2 12:33:38 2008 From: dbueno at gmail.com (Denis Bueno) Date: Sat Feb 2 12:32:47 2008 Subject: [Haskell-cafe] Refactoring from State monad to ST monad, for STUArray Message-ID: <6dbd4d000802020933s3eb42ce4ne8c0afcf305717ab@mail.gmail.com> Is it possible to use the ST monad as a (drop-in) replacement for the State monad in the following situation? If not, is there a "best practice" for refactoring? I have a bunch of functions that return state actions: type MyState = ... foo1 :: T1 -> State MyState a foo2 :: T2 -> State MyState a ... foon :: Tn -> State MyState a And I'd like to refactor this to use the ST monad, mechanically, if possible. All uses of the MyState inside State are single-threaded. In my application, MyState is a record with 5 or so fields. One of those fields uses a list to keep track of some information, and I'd like to change that to STUArray, because it changes my bottleneck operations from O(n) to O(1). This, of course, requires having the ST monad around, in order to achieve the proper time complexity. Is there an easy way to do this? In the future, should I *start out* with the ST monad if I suspect I'll need to use an imperative data structure for efficiency reasons? I started out with State because I'm modeling a transition system, so it seemed natural. Any advice is appreciated. -- Denis From duncan.coutts at worc.ox.ac.uk Sat Feb 2 12:45:02 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sat Feb 2 12:44:15 2008 Subject: [Haskell-cafe] Cabal, GHC, FFI and Visual Studio on Windows In-Reply-To: <6c0416190802020915u7a3878dbh9c3fe30f8106a3f0@mail.gmail.com> References: <47A30596.6080209@therning.org> <1201964896.13130.132.camel@localhost> <6c0416190802020915u7a3878dbh9c3fe30f8106a3f0@mail.gmail.com> Message-ID: <1201974303.13130.145.camel@localhost> On Sat, 2008-02-02 at 18:15 +0100, Felix Martini wrote: > Magnus Therning wrote: > > Is it possible to get Cabal to use 'cl' (Microsoft's C/C++ compiler > > shipped with Visual Studio Express)? > > Duncan Coutts wrote: > > The problem is to get GHC to use 'cl'. That's a longer term project that > > GHC HQ are interested in. There's something about it on the GHC dev wiki > > I think. Don't hold your breath. > > When using the native code generator only foreign C code must be > compiled with a C compiler. Presently Cabal passes C sources that are > listed in the 'c-sources' field of a cabal file to GHC. It would be > nice to have a Cabal field to specify the compiler for C sources, say > 'c-sources-compiler: msvc'. The default would still be gcc, but with a > Cabal flag the user would be able to change that to e.g. Sun's C > compiler. It would be reasonable to use the system C compiler rather than ghc, however we will have to do more work to find what extra include dirs get used and have Cabal pass those. Currently we pass the -package flags to ghc which ghc uses to look up what include dirs those packages add, and then it calls the C compiler with those extra include dirs. Cabal would have to do that itself. Duncan From derek.a.elkins at gmail.com Sat Feb 2 12:05:12 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Sat Feb 2 13:05:10 2008 Subject: [Haskell-cafe] Refactoring from State monad to ST monad, for STUArray In-Reply-To: <6dbd4d000802020933s3eb42ce4ne8c0afcf305717ab@mail.gmail.com> References: <6dbd4d000802020933s3eb42ce4ne8c0afcf305717ab@mail.gmail.com> Message-ID: <1201971913.5496.117.camel@derek-laptop> On Sat, 2008-02-02 at 12:33 -0500, Denis Bueno wrote: > Is it possible to use the ST monad as a (drop-in) replacement for the > State monad in the following situation? If not, is there a "best > practice" for refactoring? > > I have a bunch of functions that return state actions: > > type MyState = ... > > foo1 :: T1 -> State MyState a > foo2 :: T2 -> State MyState a > ... > foon :: Tn -> State MyState a > > And I'd like to refactor this to use the ST monad, mechanically, if > possible. All uses of the MyState inside State are single-threaded. > > In my application, MyState is a record with 5 or so fields. One of > those fields uses a list to keep track of some information, and I'd > like to change that to STUArray, because it changes my bottleneck > operations from O(n) to O(1). This, of course, requires having the ST > monad around, in order to achieve the proper time complexity. > > Is there an easy way to do this? In the future, should I *start out* > with the ST monad if I suspect I'll need to use an imperative data > structure for efficiency reasons? I started out with State because > I'm modeling a transition system, so it seemed natural. > > Any advice is appreciated. %s/State MyState/MyMonad s/g type MyState s = ... s ... type MyMonad s = StateT (MyState s) (ST s) From magnus at therning.org Sat Feb 2 13:50:58 2008 From: magnus at therning.org (Magnus Therning) Date: Sat Feb 2 13:50:22 2008 Subject: [Haskell-cafe] Cabal, GHC, FFI and Visual Studio on Windows In-Reply-To: <1201974303.13130.145.camel@localhost> References: <47A30596.6080209@therning.org> <1201964896.13130.132.camel@localhost> <6c0416190802020915u7a3878dbh9c3fe30f8106a3f0@mail.gmail.com> <1201974303.13130.145.camel@localhost> Message-ID: <47A4BB92.6030104@therning.org> Duncan Coutts wrote: [..] > It would be reasonable to use the system C compiler rather than ghc, > however we will have to do more work to find what extra include dirs get > used and have Cabal pass those. > > Currently we pass the -package flags to ghc which ghc uses to look up > what include dirs those packages add, and then it calls the C compiler > with those extra include dirs. Cabal would have to do that itself. Well it sounds like I'll have to settle for a two-step build procedure for the time being. Luckily I managed to recall the existence of CMake just today, so it seems I can make my Haskell-hacking-on-Windows experience somewhat bearable... /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?gmail?com http://therning.org/magnus What if I don't want to obey the laws? Do they throw me in jail with the other bad monads? -- Daveman -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080202/e0182c1d/signature.bin From duncan.coutts at worc.ox.ac.uk Sat Feb 2 14:06:41 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sat Feb 2 14:05:54 2008 Subject: [Haskell-cafe] Cabal, GHC, FFI and Visual Studio on Windows In-Reply-To: <47A4BB92.6030104@therning.org> References: <47A30596.6080209@therning.org> <1201964896.13130.132.camel@localhost> <6c0416190802020915u7a3878dbh9c3fe30f8106a3f0@mail.gmail.com> <1201974303.13130.145.camel@localhost> <47A4BB92.6030104@therning.org> Message-ID: <1201979201.13130.155.camel@localhost> On Sat, 2008-02-02 at 18:50 +0000, Magnus