Re: [Haskell-cafe] So how do people pronounce 'cabal' around here?
Not always. Just to be sure, I just checked the Longman Dictionary of Contemporary English Online (http://pewebdic2.cw.idm.fr/topbar.html), and it came up with the following pronunciation for cabal: \kəˈbæl\ In fact, this was the only pronunciation listed, so the other pronunciation is not listed at all. Here, the æ phoneme is identical to the same phoneme in balance (http://pewebdic2.cw.idm.fr/display/display.html?unfolded=3542ids=3542,3543,3549,3544,3545,3546,3547,3548,3551,3679,29605,44549,47636,48407): \ˈbæləns\ If you don't say it that way, you get kicked out of the Longman cabal. Further, I asked two professional translators/interpreters at work, and they both said that either pronunciation was correct. Which cabal did you mean? Benjamin L. Russell --- On Wed, 5/28/08, Clifford Beshers [EMAIL PROTECTED] wrote: From: Clifford Beshers [EMAIL PROTECTED] Subject: Re: [Haskell-cafe] So how do people pronounce 'cabal' around here? To: haskell-cafe@haskell.org Date: Wednesday, May 28, 2008, 2:30 PM On Tue, May 27, 2008 at 10:27 PM, Benjamin L. Russell [EMAIL PROTECTED] wrote: Actually, according to the definition that you used ( http://www.merriam-webster.com/dictionary/cabal), there are the following two pronunciations of cabal: 1) \kə-ˈbäl\ 2) \kə-ˈbal\ The a phoneme of the ˈbal syllable of pronunciation 2 is actually defined to be identical to the first syllable ˈba of balance ( http://www.merriam-webster.com/dictionary/balance); viz.: \ˈba-lən(t)s\ But if you say it that way, you get kicked out of the cabal.___ 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
[Haskell-cafe] re: a build problem
Hi Duncan, In response to your below, I am running runhaskell Setup.hs configure -v3 --prefix=$HOME. Is v3 the current highest Cabal highest verbosity level? FYI basically I am running ghc that I just built a couple of days ago from the ghc source distribution. Vasili (I. Galchin) ;^) On Tue, 2008-05-27 at 15:33 -0700, Thomas Hartman wrote: I think dist gets populated when you do build. Actually we also stash the configuration in ./dist/setup-config so that gets created at configure time. Galchin's problem is that something goes wrong during the configure and so nothing gets created in dist. From the log it looks like ghc or ld are failing during one of the early tests we do when configuring ghc. To make debugging this kind of thing a bit less mysterious in future Cabal now logs in greater detail what happens when it calls external programs (when invoked at the highest verbosity level). Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lazy lists simulated by unboxed mutable arrays
Hello Henning, Wednesday, May 28, 2008, 9:51:28 AM, you wrote: We could simulate a list with strict elements, i.e. data StrictList a = Elem !a (StrictList a) | End by an unboxed array with a cursor to the next element to be evaluated and a function that generates the next element. Whenever an element with an index beyond the cursor is requested, sufficiently many new elements are written to the array and the cursor is advanced. This would still allow the nice tricks for recursive Fibonacci sequence definition. This will obviously save memory, but can we also expect that it is noticeably faster than (StrictList a) ? looks like lazy.bytestring generalized to any a -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] What's NaN?
Hello Why does sqrt (-16) return NaN? What is NaN? Thanks Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What's NaN?
Quoth PR Stanley on Wed, May 28, 2008 at 08:04:44 +0100 Hello Why does sqrt (-16) return NaN? What is NaN? NaN stands for Not a Number. See the complex library for how to have complex numbers. -- [EMAIL PROTECTED] -= H+ =- www.kierun.org PGP: 009D 7287 C4A7 FD4F 1680 06E4 F751 7006 9DE2 6318 pgpzsKbaJOQdu.pgp Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: a build problem
In order to save everybody on Haskell Cafe a lot of time, I bootstrapped my ghc from Ubuntu ghc 6.8.2 using source from http://www.haskell.org. Regards, Vasili On Wed, May 28, 2008 at 1:14 AM, Galchin, Vasili [EMAIL PROTECTED] wrote: Hi Duncan, In response to your below, I am running runhaskell Setup.hs configure -v3 --prefix=$HOME. Is v3 the current highest Cabal highest verbosity level? FYI basically I am running ghc that I just built a couple of days ago from the ghc source distribution. Vasili (I. Galchin) ;^) On Tue, 2008-05-27 at 15:33 -0700, Thomas Hartman wrote: I think dist gets populated when you do build. Actually we also stash the configuration in ./dist/setup-config so that gets created at configure time. Galchin's problem is that something goes wrong during the configure and so nothing gets created in dist. From the log it looks like ghc or ld are failing during one of the early tests we do when configuring ghc. To make debugging this kind of thing a bit less mysterious in future Cabal now logs in greater detail what happens when it calls external programs (when invoked at the highest verbosity level). Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Type Coercion
Hi (16 :: Float) is a perfectly legitimate statement although I'm surprised that it's allowed in a type strong language such as Haskell. It's a bit like casting in good old C. What's going on here? Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type Coercion
On 28 May 2008, at 09:34, PR Stanley wrote: Hi (16 :: Float) is a perfectly legitimate statement although I'm surprised that it's allowed in a type strong language such as Haskell. It's a bit like casting in good old C. What's going on here? It's not a coercion -- it happens at compile time. In a coercion, 16 starts off it's runtime life as an integer, gets a couple of things done to it, and then is coerced into a floating point number. What's happening here is you are telling the compiler I would like the number 16, but a floating point version of it please. That instance of 16 always will have type Float. Slightly more detail: numeric literals like this normally have the type Int, but get pre-processed by the compiler. Whenever you write 16, the compiler writes (fromInteger 16). This has the effect that instead of having the type Int, your literal has the type Num a = a. You adding the type signature constrains it to being a Float again. Bob ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What's NaN?
Try reading http://www.physics.ohio-state.edu/~dws/grouplinks/floating_point_math.pdf On Wed, May 28, 2008 at 8:04 AM, PR Stanley [EMAIL PROTECTED] wrote: Hello Why does sqrt (-16) return NaN? What is NaN? Thanks Paul ___ 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
Re: [Haskell-cafe] Re: the Network.URI parser
On 28/05/2008, at 12:28 PM, Miguel Mitrofanov wrote: I am taking comments on a web forum from arbitrary people. The interpretation of the HTML occurs at the user's browser. A lot of people will be using outdated browsers (IE 5.5 / 6), ergo security (at the source) becomes my problem. I cannot force them to upgrade their browsers. I think this is very wrong for two reasons. First of all, the more web sites care of old browsers, the later people will upgrade them, therefore preventing the progress in Web (though IE 5.5 is not THAT old and bad, so this argument is not so strong). In Russia we some times say that a user with an outdated browser is an EPTH (Evil Pinocchio To Himself, don't ask me about source of this term). I am not encouraging people to stick with IE 5.5, I am trying to prevent them from being exploited when visiting my site. It is a good- faith-best-effort, not something I will formally prove. Secondly, I don't think that filtering HTML coming from an arbitrary user is a good idea. HTML is not very human-readable and too complex to achieve real safety without lots of work. My suggestion is to use some home-grown wiki-like syntax - it's easier to enter (*bold* instead of bbold/b), easier to read (and your users would sometimes read their comments before posting - to check correctness), and easier to process, since it can't have security holes you're not aware of. Did you read my post? I validate the XHTML against a restricted variant of the XHTML 1.0 Strict DTD. I want to ensure that if it validates, it is safe, as I explained before. I think the style attribute is unsafe, so I can remove it from the DTD. (We can simulate the effect of style by providing pre-made CSS classes and vetting the class attribute.) I am sure you can generalise from here. As for some other kind of markup: if my users were sophisticated enough to use something else, then I would use it. The target audience is not very literate, let alone computer literate. But you're right, we are off topic. Sorry to reply to your post then, I couldn't resist. :-/ cheers peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type Coercion
PR Stanley [EMAIL PROTECTED] writes: (16 :: Float) is a perfectly legitimate statement although I'm surprised that it's allowed in a type strong language such as Haskell. It's a bit like casting in good old C. What's going on here? The literal 16 is really shorthand for fromIntegral (16::Integer)¹, which is a perfectly good expression for any member of the Num class -- including Float. -k ¹ Possibly it's ::Int? -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type Coercion
2008/5/28 PR Stanley [EMAIL PROTECTED]: Hi (16 :: Float) is a perfectly legitimate statement although I'm surprised that it's allowed in a type strong language such as Haskell. It's a bit like casting in good old C. What's going on here? Don't worry: it's not a cast. Numeric constants like 16 in Haskell have polymorphic types: Prelude :t 16 16 :: (Num t) = t Prelude :t 16.6 16.6 :: (Fractional t) = t Writing 16 :: Float you are simply making the type explicit, and you can do it only in the context of the typeclass. Prelude :t (16 :: Integer) (16 :: Integer) :: Integer This works because Integer is a type of the typeclass Num, but: Prelude :t (16.5 :: Integer) interactive:1:1: No instance for (Fractional Integer) arising from the literal `16.5' at interactive:1:1-4 Possible fix: add an instance declaration for (Fractional Integer) This doesn't work. So everything is done at compile time, no casting (i.e. believe me compiler, this it a Float) involved. Notice that during binding the numeric constants' type is always made explicit (if you want to know more, look for section 4.3.4 in the Haskell Report): Prelude let a = 3 Prelude :t a a :: Integer Prelude let b = 3.3 Prelude :t b b :: Double Prelude b :: Float interactive:1:0: Couldn't match expected type `Float' against inferred type `Double' In the expression: b :: Float In the definition of `it': it = b :: Float Salvatore ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lazy lists simulated by unboxed mutable arrays
On Wed, 28 May 2008, Bulat Ziganshin wrote: Hello Henning, Wednesday, May 28, 2008, 9:51:28 AM, you wrote: We could simulate a list with strict elements, i.e. data StrictList a = Elem !a (StrictList a) | End by an unboxed array with a cursor to the next element to be evaluated and a function that generates the next element. Whenever an element with an index beyond the cursor is requested, sufficiently many new elements are written to the array and the cursor is advanced. This would still allow the nice tricks for recursive Fibonacci sequence definition. This will obviously save memory, but can we also expect that it is noticeably faster than (StrictList a) ? looks like lazy.bytestring generalized to any a As far as I know, ByteString.Lazy is chunky, that is laziness occurs only every 1000th byte or so. My suggestion aims at laziness at element level but still more efficiency than a list. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Lazy lists simulated by unboxed mutable arrays
Hello Henning, Wednesday, May 28, 2008, 12:22:54 PM, you wrote: Whenever an element with an index beyond the cursor is requested, sufficiently many new elements are written to the array and the cursor is advanced. As far as I know, ByteString.Lazy is chunky, that is laziness occurs only every 1000th byte or so. My suggestion aims at laziness at element level but still more efficiency than a list. well, i don't understand difference between your idea and lazybs implementation -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Examples of using Haskell for mathematics
Hi On 28 May 2008, at 10:33, Jose A. Ortega Ruiz wrote: [..] I've enjoyed immensely several entries in Dan Piponi's 'A Neighborhood of Infinity'. In particular, 'Infinitesimal rotations and Lie algebras': http://sigfpe.blogspot.com/2008/04/infinitesimal-rotations-and- lie.html made me decide once and for all that i want to grok Haskell. It's this sort of positivity that prompted us to invite Dan to speak at MSFP 2008 in Iceland. His blog is full of such lovely connections between functional programming and mathematics: it is a source of much happiness and wonder. Shameless plug. http://msfp.org.uk/ Conor ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Aren't type system extensions fun? [Further analysis]
Andrew Coppin wrote: (id 'J', id True) -- Works perfectly. \f - (f 'J', f True) -- Fails miserably. Both expressions are obviously perfectly type-safe, and yet the type checker stubbornly rejects the second example. Clearly this is a flaw in the type checker. When you type some expression such as \x - x you have to choose among an infinite number of valid types for it: Int - Int Char - Char forall a . a - a forall a b . (a,b) - (a,b) ... Yet the type inference is smart enough to choose the best one: forall a. a - a because this is the most general type. Alas, for code like yours: foo = \f - (f 'J', f True) there are infinite valid types too: (forall a. a - Int) - (Int, Int) (forall a. a - Char)- (Char, Char) (forall a. a - (a,a)) - ((Char,Char),(Bool,Bool)) ... and it is much less clear if a best, most general type exists at all. You might have a preference to type it so that foo :: (forall a . a-a) - (Char,Bool) foo id == ('J',True) :: (Char,Bool) but one could also require the following, similarly reasonable code to work: foo :: (forall a. a - (a,a)) - ((Char,Char),(Bool,Bool)) foo (\y - (y,y)) == (('J','J'),(True,True)) :: ((Char,Char),(Bool,Bool)) And devising a type inference system allowing both seems to be quite hard. Requiring a type annotation for these not-so-common code snippets seems to be a fair compromise, at least to me. Regards, Zun. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lazy lists simulated by unboxed mutable arrays
Bulat Ziganshin [EMAIL PROTECTED] writes: well, i don't understand difference between your idea and lazybs implementation HT said earlier that: This would still allow the nice tricks for recursive Fibonacci sequence definition. Which I guess refers to something like: fibs = 1 : 1 : zipWith (+) fibs (tail fibs) I don't think you can do that with LBS, since you'd need to calculate a whole chunk at a time, and for any chunk size 1, each chunk depends on itself. -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lazy lists simulated by unboxed mutable arrays
On Wed, 28 May 2008, Duncan Coutts wrote: On Wed, 2008-05-28 at 10:22 +0200, Henning Thielemann wrote: On Wed, 28 May 2008, Bulat Ziganshin wrote: Hello Henning, Wednesday, May 28, 2008, 9:51:28 AM, you wrote: We could simulate a list with strict elements, i.e. data StrictList a = Elem !a (StrictList a) | End by an unboxed array with a cursor to the next element to be evaluated and a function that generates the next element. Whenever an element with an index beyond the cursor is requested, sufficiently many new elements are written to the array and the cursor is advanced. This would still allow the nice tricks for recursive Fibonacci sequence definition. This will obviously save memory, but can we also expect that it is noticeably faster than (StrictList a) ? looks like lazy.bytestring generalized to any a As far as I know, ByteString.Lazy is chunky, that is laziness occurs only every 1000th byte or so. My suggestion aims at laziness at element level but still more efficiency than a list. How about a chunky lazy array? The problem with lazy bytestring is that each chunk is strict but if you made each chunk a H98 lazy array that might work nicely. This would actually yield the intended result, but I'm afraid there are still too much pointers and allocations around. The nice thing about my suggestion is, that no allocation would be needed to construct new elements in the list, just running the function to evaluate the next elements and advance the cursor. It's a hack of course, like ByteString internally is, it's entirely for efficiency reasons. I interpret your answers as what you suggest is not obviuous and has probably not been proposed before so I'll take some time for a demonstration implementation. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: static linking
Hello, Further on my static linking woes: debian ~$ ghc --version The Glorious Glasgow Haskell Compilation System, version 6.8.2 -debian ~$ cat T.hs main :: IO () main = putStrLn Hello world -debian ~$ ghc -optl-static -static --make T.hs Linking T ... /usr/lib/gcc/i486-linux-gnu/4.2.3/../../../../lib/ librt.a(timer_create.o): In function `timer_create': (.text+0x107): undefined reference to `pthread_once' ... references to missing pthread symbols Does anyone have static linking working for GHC 6.8.2 and can inform me of the magic incantation? Get the latest development version from darcs, perhaps? BTW when I said move to the end, I meant move to the end of -l flags. cheers peter On 27/05/2008, at 10:37 AM, Peter Gammie wrote: Hello, I am having a bit of trouble static linking my program using GHC 6.8.2. In brief: rt uses pthread, but -lrt is the final thing on the command line passed to the linker, and so the pthread symbols are not resolved. Manually moving -lpthread to the end of the collect2 command line does the trick. The question is how to do this using ghc. This is on Debian, using the 6.8.2-5 from unstable. I can provide the command lines if that is helpful. Note the same setup worked fine under GHC 6.6.1. cheers peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lazy lists simulated by unboxed mutable arrays
Ketil Malde [EMAIL PROTECTED] writes: You've lost me at least. ...but perhaps I can find my way back on my own? Today, you can choose between Array, with lazy elements, or UArray, with strict elements. Lazy arrays have the elements defined in advance, strict ones have them calculated in advance - with the tremendous advantage of being able to eliminate the pointer for each element. Otherwise a pointer is needed to point to a potentially unevaluated thunk. Perhaps there is a middle ground here, if you add the restriction that the elements are generated in order? This way, you only need one pointer to an unevaluated thunk (which will yield all remaining elements as needed), and an unboxed array can contain the calculated values. This would be very nice for e.g. sequence alignment, where the alignment matrix is self-referencing, but the pointers represent a very real cost to an already expensive (resource-intesive) solution. -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Benchmarking Framework
I am in the process of writing a library for my MSc dissertation and would like to do some benchmarking. In doing so I need to compare the time and space of my library with some other code. Is there a framework for doing so in Haskell, aside from the Profiling tools in GHC? Basically I'm looking for something like QuickCheck, but that helps with generating repeatable tests to measure performance. Is there anything out there that anyone would recommend? -- Tom Harper MSc Computer Science '08 University of Oxford Mobile: +44 (0)7533 998 591 Skype: +1 949 273 4627 (harpertom) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Benchmarking Framework
Tom Harper [EMAIL PROTECTED] writes: I am in the process of writing a library for my MSc dissertation and would like to do some benchmarking. In doing so I need to compare the time and space of my library with some other code. Is there a framework for doing so in Haskell, aside from the Profiling tools in GHC? Basically I'm looking for something like QuickCheck, but that helps with generating repeatable tests to measure performance. Is there anything out there that anyone would recommend? I've hacked around with QuickCheck to run somewhat more predictable tests with timing results. It's not beautiful, but if it's any help: http://malde.org/~ketil/biohaskell/biolib/Test/QuickBench.hs ^ (the URL up until here + is the darcs archive, should you want to look at the whole thing in context) -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lazy lists simulated by unboxed mutable arrays
On Wed, 2008-05-28 at 10:22 +0200, Henning Thielemann wrote: On Wed, 28 May 2008, Bulat Ziganshin wrote: Hello Henning, Wednesday, May 28, 2008, 9:51:28 AM, you wrote: We could simulate a list with strict elements, i.e. data StrictList a = Elem !a (StrictList a) | End by an unboxed array with a cursor to the next element to be evaluated and a function that generates the next element. Whenever an element with an index beyond the cursor is requested, sufficiently many new elements are written to the array and the cursor is advanced. This would still allow the nice tricks for recursive Fibonacci sequence definition. This will obviously save memory, but can we also expect that it is noticeably faster than (StrictList a) ? looks like lazy.bytestring generalized to any a As far as I know, ByteString.Lazy is chunky, that is laziness occurs only every 1000th byte or so. My suggestion aims at laziness at element level but still more efficiency than a list. How about a chunky lazy array? The problem with lazy bytestring is that each chunk is strict but if you made each chunk a H98 lazy array that might work nicely. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: static linking
Peter Gammie wrote: Hello, Further on my static linking woes: debian ~$ ghc --version The Glorious Glasgow Haskell Compilation System, version 6.8.2 -debian ~$ cat T.hs main :: IO () main = putStrLn Hello world -debian ~$ ghc -optl-static -static --make T.hs Linking T ... /usr/lib/gcc/i486-linux-gnu/4.2.3/../../../../lib/librt.a(timer_create.o): In function `timer_create': (.text+0x107): undefined reference to `pthread_once' ... references to missing pthread symbols Does anyone have static linking working for GHC 6.8.2 and can inform me of the magic incantation? Get the latest development version from darcs, perhaps? BTW when I said move to the end, I meant move to the end of -l flags. We may need to tweak the order of the libraries in rts/package.conf.in (this is where -lrt comes from). The question is, do we need a configure test? Cheers, Simon cheers peter On 27/05/2008, at 10:37 AM, Peter Gammie wrote: Hello, I am having a bit of trouble static linking my program using GHC 6.8.2. In brief: rt uses pthread, but -lrt is the final thing on the command line passed to the linker, and so the pthread symbols are not resolved. Manually moving -lpthread to the end of the collect2 command line does the trick. The question is how to do this using ghc. This is on Debian, using the 6.8.2-5 from unstable. I can provide the command lines if that is helpful. Note the same setup worked fine under GHC 6.6.1. cheers peter ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Examples of using Haskell for mathematics
Brent Yorgey [EMAIL PROTECTED] writes: Hi all! In a couple weeks I will be giving a short (15-min.) talk to an audience of mostly mathematicians, entitled Executable Mathematics: A Whirlwind Introduction to Haskell. The idea will be to give a flavor of Haskell, its uniquenesses, and why it is a great language for playing around with mathematics, by way of some well-chosen examples. There are definitely plenty of such examples out there, and I've already found quite a few that I might use, but I thought I would send an email to the cafe to ask whether anyone has any code which you think particularly exemplifies some aspect of why Haskell is a great language for mathematics. I'm looking to include a wide range of examples, so any length (from a few to hundreds of lines of code) and any level (from simple number theory to things only a few people in the world understand) are fair game. I've enjoyed immensely several entries in Dan Piponi's 'A Neighborhood of Infinity'. In particular, 'Infinitesimal rotations and Lie algebras': http://sigfpe.blogspot.com/2008/04/infinitesimal-rotations-and-lie.html made me decide once and for all that i want to grok Haskell. HTH, jao -- Go to Heaven for the climate, Hell for the company. - Mark Twain ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lazy lists simulated by unboxed mutable arrays
Henning Thielemann [EMAIL PROTECTED] writes: We could simulate a list with strict elements, i.e. data StrictList a = Elem !a (StrictList a) | End by an unboxed array with a cursor to the next element to be evaluated and a function that generates the next element. [...] looks like lazy.bytestring generalized to any a As far as I know, ByteString.Lazy is chunky, that is laziness occurs only every 1000th byte or so. My suggestion aims at laziness at element level but still more efficiency than a list. You've lost me at least. Presumably, you don't want single-element UArrays, so you want a chunky data structure, but fine-grained laziness. As far as I can tell, this implies that the UArray is split (at the position indicated by the cursor?) into an evaluated part, and an unevaluated part. Now, if you evaluate one more element, you need to calculate its value and create a new UArray (and cursor) to replace the old one(s). Unless you do the whole thing in the ST or IO monads, I can't see how you can implement this efficiently. Where did I misunderstand you? Perhaps you can sketch some code? -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lazy lists simulated by unboxed mutable arrays
On Wed, 28 May 2008, Ketil Malde wrote: Bulat Ziganshin [EMAIL PROTECTED] writes: well, i don't understand difference between your idea and lazybs implementation HT said earlier that: This would still allow the nice tricks for recursive Fibonacci sequence definition. Which I guess refers to something like: fibs = 1 : 1 : zipWith (+) fibs (tail fibs) I don't think you can do that with LBS, since you'd need to calculate a whole chunk at a time, and for any chunk size 1, each chunk depends on itself. Right, that's what I meant. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type Coercion
To add to this: There are other constants which are polymorphic, not only numbers. Examples where you could add type signatures to make the type explicit are the empty list '[]' and the 'Nothing' constructor of 'Maybe a'. Adding type signatures to these will not be type casts, but telling the compiler that you want to specialize the given polymorphic entity. Abhay On Wed, May 28, 2008 at 1:27 PM, Salvatore Insalaco [EMAIL PROTECTED] wrote: 2008/5/28 PR Stanley [EMAIL PROTECTED]: Hi (16 :: Float) is a perfectly legitimate statement although I'm surprised that it's allowed in a type strong language such as Haskell. It's a bit like casting in good old C. What's going on here? Don't worry: it's not a cast. Numeric constants like 16 in Haskell have polymorphic types: Prelude :t 16 16 :: (Num t) = t Prelude :t 16.6 16.6 :: (Fractional t) = t Writing 16 :: Float you are simply making the type explicit, and you can do it only in the context of the typeclass. Prelude :t (16 :: Integer) (16 :: Integer) :: Integer This works because Integer is a type of the typeclass Num, but: Prelude :t (16.5 :: Integer) interactive:1:1: No instance for (Fractional Integer) arising from the literal `16.5' at interactive:1:1-4 Possible fix: add an instance declaration for (Fractional Integer) This doesn't work. So everything is done at compile time, no casting (i.e. believe me compiler, this it a Float) involved. Notice that during binding the numeric constants' type is always made explicit (if you want to know more, look for section 4.3.4 in the Haskell Report): Prelude let a = 3 Prelude :t a a :: Integer Prelude let b = 3.3 Prelude :t b b :: Double Prelude b :: Float interactive:1:0: Couldn't match expected type `Float' against inferred type `Double' In the expression: b :: Float In the definition of `it': it = b :: Float Salvatore ___ 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
Re: [Haskell-cafe] So how do people pronounce 'cabal' around here?
2008/5/28 Clifford Beshers [EMAIL PROTECTED]: But if you say it that way, you get kicked out of the cabal. I thought the first rule was There is no cabal. Oh wait, that's Debian. Oh wait... aa! -- Darrin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] is there some book about haskell and data struct and alg?
is there some book about haskell and data struct and alg? i mean data struct and algorithm in haskell i am freshman i want to study haskell with data struct and alg -- Hu Jinpu (nickname: smellcode) Web developer email =~ /(^hujinpu)\@(gmail)\.(com)$/ or email.gsub!(/hujinpu/, 'smellcode') http://hujinpu.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] is there some book about haskell and data struct and alg?
Hi, Purely Functional Data Structures by Chris Okasaki is a good one. Here is a link to it on Amazon: http://www.amazon.com/Purely-Functional-Structures-Chris-Okasaki/dp/0521663504 Good luck! -Iavor 2008/5/28 smellcode [EMAIL PROTECTED]: is there some book about haskell and data struct and alg? i mean data struct and algorithm in haskell i am freshman i want to study haskell with data struct and alg -- Hu Jinpu (nickname: smellcode) Web developer email =~ /(^hujinpu)\@(gmail)\.(com)$/ or email.gsub!(/hujinpu/, 'smellcode') http://hujinpu.net ___ 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
Re: [Haskell-cafe] is there some book about haskell and data struct and alg?
2008/5/28 Iavor Diatchki [EMAIL PROTECTED]: Hi, Purely Functional Data Structures by Chris Okasaki is a good one. Here is a link to it on Amazon: http://www.amazon.com/Purely-Functional-Structures-Chris-Okasaki/dp/0521663504 Good luck! -Iavor Argh, I'm predated by a few seconds! :-) Before buying the book (I did), you may want to check the slightly different pdf: http://www.cs.cmu.edu/~rwh/theses/okasaki.pdf 2008/5/28 smellcode [EMAIL PROTECTED]: is there some book about haskell and data struct and alg? i mean data struct and algorithm in haskell i am freshman i want to study haskell with data struct and alg -- Hu Jinpu (nickname: smellcode) Web developer email =~ /(^hujinpu)\@(gmail)\.(com)$/ or email.gsub!(/hujinpu/, 'smellcode') http://hujinpu.net ___ 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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] is there some book about haskell and data struct and alg?
smellcode wrote: is there some book about haskell and data struct and alg? i mean data struct and algorithm in haskell i am freshman i want to study haskell with data struct and alg I expect this is obvious, but just in case, there is a list here http://haskell.org/haskellwiki/Books which may help. I found Hutton to be an easier read than Hudak, but Hudak contains some very wonderful things. I look forward to the new book which you can see bits of here http://www.realworldhaskell.org/blog/ Richard. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Benchmarking Framework
On Wed, May 28, 2008 at 11:41:34AM +0100, Tom Harper wrote: I am in the process of writing a library for my MSc dissertation and would like to do some benchmarking. In doing so I need to compare the time and space of my library with some other code. Is there a framework for doing so in Haskell, aside from the Profiling tools in GHC? Basically I'm looking for something like QuickCheck, but that helps with generating repeatable tests to measure performance. Is there anything out there that anyone would recommend? Also have a look at smallcheck (hackage) then. It has been announced on the haskell mailinglist recently; SmallCheck is similar to QuickCheck (Claessen and Hughes 2000-) but instead of testing for a sample of randomly generated values, SmallCheck tests properties for all the finitely many values up to some depth, progressively increasing the depth used Marc Weber ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lazy lists simulated by unboxed mutable arrays
lemming: I wonder whether the following idea has been investigated or implemented somewhere: We could simulate a list with strict elements, i.e. data StrictList a = Elem !a (StrictList a) | End I've used the above structure itself, as a useful alternative to fully lazy lists. by an unboxed array with a cursor to the next element to be evaluated and a function that generates the next element. Whenever an element with an index beyond the cursor is requested, sufficiently many new elements are written to the array and the cursor is advanced. This would still allow the nice tricks for recursive Fibonacci sequence definition. This will obviously save memory, but can we also expect that it is noticeably faster than (StrictList a) ? That sounds a lot like the semi-eager structure, Lazy ByteStrings, which do cache sized chunks of evaluation before suspending. With the cursor in place, it would behave more like the buffer abstraction to lazy bytestrings in Data.Binary? -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lazy lists simulated by unboxed mutable arrays
On Wed, 28 May 2008, Ketil Malde wrote: Ketil Malde [EMAIL PROTECTED] writes: You've lost me at least. ...but perhaps I can find my way back on my own? Today, you can choose between Array, with lazy elements, or UArray, with strict elements. ... and ByteStrings, where in principle the elements could be initialized in any order, but actually the ByteString functions prefer a left-to-right order. They are clearly intended as list replacement, so my proposed cursor arrays would do as well. Lazy arrays have the elements defined in advance, strict ones have them calculated in advance - with the tremendous advantage of being able to eliminate the pointer for each element. Otherwise a pointer is needed to point to a potentially unevaluated thunk. Perhaps there is a middle ground here, if you add the restriction that the elements are generated in order? Exactly. Thus I compared my suggestion with element-strict lists. This way, you only need one pointer to an unevaluated thunk (which will yield all remaining elements as needed), and an unboxed array can contain the calculated values. That's it! This would be very nice for e.g. sequence alignment, where the alignment matrix is self-referencing, but the pointers represent a very real cost to an already expensive (resource-intesive) solution. I'm thinking about signal processing, where data is processed in time order in many cases. Thank you for clarification! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lazy lists simulated by unboxed mutable arrays
On Wed, 28 May 2008, Don Stewart wrote: by an unboxed array with a cursor to the next element to be evaluated and a function that generates the next element. Whenever an element with an index beyond the cursor is requested, sufficiently many new elements are written to the array and the cursor is advanced. This would still allow the nice tricks for recursive Fibonacci sequence definition. This will obviously save memory, but can we also expect that it is noticeably faster than (StrictList a) ? That sounds a lot like the semi-eager structure, Lazy ByteStrings, which do cache sized chunks of evaluation before suspending. With the cursor in place, it would behave more like the buffer abstraction to lazy bytestrings in Data.Binary? Can you code fibs = 0 : 1 : zipWith (+) fibs (tail fibs) with hte 'buffer'? I'm afraid you cannot simultaneously read and write from 'buffer', cannot 'drop' and so on, right? What I have in mind is some combination of a 'Data.Stream' for generating the data (playing the role of the unevaluated thunk), a memory chunk for buffering calculated data and a wrapper which provides a view on a sub-array. Ideally 'fibs' would be translated to something like int *p = malloc ...; int *p0 = p; *p = 0; p++; int *p1 = p; *p = 1; p++; int *p2 = p; int i=n; while (i0) { *p2 = *p0 + *p1; p0++; p1++; p2++; i--; } I'm not sure, whether the compiler can eliminate the last bit of laziness that would remain in a 'cursor array'. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type Coercion
PR Stanley wrote: Hi (16 :: Float) is a perfectly legitimate statement although I'm surprised that it's allowed in a type strong language such as Haskell. It's a bit like casting in good old C. What's going on here? It's not a type cast, it's a class method: class Num n where ... fromInteger :: Integer - n ... The literal 16 is interpretted as the function call fromInteger 16. If you write a literal, the compiler will usually optimise away the function call leaving only a literal Float/Double/Int/Word16/whatever. Notice, however, that you can explicitly call this function yourself at any time to change the type of something. Note that this is *not* a type cast. It doesn't just change what type the type checker thinks the data is; it really does change the actual bit pattern in memory. (E.g., turning an Integer into a Word8, possibly causing the value to overflow and wrap around in the process!) It's really no more mysterious than the way show can transform many kinds of data into a String, and read can transform them back again. It's not bypassing the type system, it's doing a real type conversion. I hope that made sense... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lazy lists simulated by unboxed mutable arrays
Bulat Ziganshin wrote: Hello Henning, looks like lazy.bytestring generalized to any a That sounds like a darn useful thing to have... [OTOH, currently unboxed arrays are available only for a select few types, so good luck implementing this in a clean way!] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Aren't type system extensions fun? [Further insight]
Luke Palmer wrote: When you're reasoning about this, I think it would help you greatly to explicitly put in *all* the foralls. In haskell, when you write, say: map :: (a - b) - [a] - [b] All the free variables are *implicitly* quantified at the top level. That is, when you write the above, the compiler sees: map :: forall a b. (a - b) - [a] - [b] And the type you mention above for the strange expression is: forall x. (x - x) - (Char, Bool) Which indicates that the caller gets to choose. That is, if a caller sees a 'forall' at the top level, it is allowed to instantiate it with whatever type it likes. Whereas the type you want has the forall in a different place than the implicit quantifiaction: (forall x. x - x) - (Char, Bool) Here the caller does not have a forall at the top level, it is hidden inside a function type so the caller cannot instantiate the type. However, when implementing this function, the argument will now have type forall x. x - x And the implementation can instantiate x to be whatever type it likes. Hmm. Right. So you're saying that the exact position of the forall indicates the exact time when the variable(s) get specific types assigned to them? So... the deeper you nest the foralls, the longer those variables stay unbound? [And the higher the rank of the type?] Finally, that seems to make actual sense. I have one final question though: forall x, y. x - y - Z forall x. x - (forall y. y - Z) Are these two types the same or different? [Ignoring for a moment the obvious fact that you'll have one hell of a job writing a total function with such a type!] After all, ignoring the quantification, we have x - y - Z x - (y - Z) which are both the same type. So does that mean you can move the forall to the left but not to the right? Or are the types actually different? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lazy lists simulated by unboxed mutable arrays
bulat.ziganshin: Hello Andrew, Wednesday, May 28, 2008, 10:37:47 PM, you wrote: looks like lazy.bytestring generalized to any a That sounds like a darn useful thing to have... well, support on only Word8 as base type isn't some fundamental limit, just creators of bytestring package was not very interested in support of other base types [OTOH, currently unboxed arrays are available only for a select few types, so good luck implementing this in a clean way!] a few years ago, storable array was slower than special primitives created for UArray implementation. now they should have equal performance, so it's possible to make UArray implementation that will work with any Storable type. Simon, can you please confirm or refute this? Sure. I've been working on a general vector library based on a similar type to STUArray, but pure, with a bytestring-like interface. http://code.haskell.org/~dons/uvector Generalised unlifted vectors. Performance looks rather good (typically loops unfold into register variables). This is a restricted form of the general data parallel arrays library. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lazy lists simulated by unboxed mutable arrays
Don Stewart [EMAIL PROTECTED] writes: http://code.haskell.org/~dons/uvector http://code.haskell.org/~dons/code/uvector (I presume? The other URL gives a 404) -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] An alternative break
Hello, I need a break function that splits the list one element further than the ordinary break. This is the simplest solution I could imagine: breakI :: (a - Bool) - [a] - ([a], [a]) breakI p s = case break p s of ([], []) - ([], []) (x, []) - (x, []) (x, l) - (x ++ [head l], tail l ) Is there a better way to write this ? thanks in advance, Pieter -- Pieter Laeremans [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] An alternative break
On Wed, May 28, 2008 at 2:53 PM, Pieter Laeremans [EMAIL PROTECTED] wrote: Hello, I need a break function that splits the list one element further than the ordinary break. This is the simplest solution I could imagine: breakI :: (a - Bool) - [a] - ([a], [a]) breakI p s = case break p s of ([], []) - ([], []) (x, []) - (x, []) (x, l) - (x ++ [head l], tail l ) Is there a better way to write this ? Your first two cases are redundant; you can eliminate the first one. Other than that, it looks fine. thanks in advance, Pieter -- Pieter Laeremans [EMAIL PROTECTED] ___ 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
Re: [Haskell-cafe] An alternative break
Hi, Am Mittwoch, den 28.05.2008, 23:53 +0200 schrieb Pieter Laeremans: Hello, I need a break function that splits the list one element further than the ordinary break. This is the simplest solution I could imagine: breakI :: (a - Bool) - [a] - ([a], [a]) breakI p s = case break p s of ([], []) - ([], []) (x, []) - (x, []) (x, l) - (x ++ [head l], tail l ) Is there a better way to write this ? appending an element to a list is expensive, so if this is a problem you can try this: breakI _ [] = ([], []) breakI p (x:xs') | p x= ([x],xs') | otherwise = let (ys,zs) = breakI p xs' in (x:ys,zs) It is basically the Prelude.break from http://haskell.org/ghc/docs/latest/html/libraries/base/src/GHC-List.html#break with the forth line (with p x) changed. Greetings, Joachim -- Joachim nomeata Breitner mail: [EMAIL PROTECTED] | ICQ# 74513189 | GPG-Key: 4743206C JID: [EMAIL PROTECTED] | http://www.joachim-breitner.de/ Debian Developer: [EMAIL PROTECTED] signature.asc Description: Dies ist ein digital signierter Nachrichtenteil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Aren't type system extensions fun? [Further insight]
These things become easier if you are explicit about type applications (which Haskell isn't). Phillippa mentioned it in an earlier post, but here it is again. First the old stuff, if you have a term of type (S-T) then the (normal form of) term must be (\ x - e), where x has type S and e has type T. When using a function it's the caller that decided the actual value of the x, and the callee decides the value to return. OK, now forall. If a term is of type (forall a . T) then the (normal form of) term must be (/\ a - e), where /\ is a capital lambda, and it means it's a function that takes a type as the argument instead of a term. For type application I'll write [EMAIL PROTECTED], meaning that f is /\ function and we give it type argument T. Let's try it on some functions. What's the real type id? It's id :: forall a . a- a since the type is a forall, the body of the function must start with a /\ id = /\ b - \ x - x (or if you want to be explicit about types id= /\ b - \ (x::b) - x) It's quite clear that the caller gets to pick both the type argument and the value argument, and the id function only gets to pick the return value, e.g., ([EMAIL PROTECTED] 5) or ([EMAIL PROTECTED] True). Another example const :: forall a . forall b . a - b - a const = /\ a - /\ b - \ x - \ y - x or, alternatively const' :: forall a . a - forall b . b - a const' = /\ a - \ x - /\ b - \ y - x It's obvious that the caller gets to pick both types and both values. The placement of the foralls only affect the type application order ([EMAIL PROTECTED]@Bool 5 True) resp (const'@Int 5 @Bool True). All right, so let's do rank 2. f :: (forall a . a - a) - (Int, Bool) What's the body of the function? The top level type is - so it must start with a \, e.g., \ g - When using g it must be used correctly. The type of g starts with a forall, so using it must start with a type application followed by a normal application. f = \ g - ([EMAIL PROTECTED] 5, [EMAIL PROTECTED] True) So it's again clear the the caller of f doesn't get to pick the type a, it must be supplied by the callee. The caller of f must supply a value of type (forall a . a-a), i.e., (f id). So you can see that depending on the forall's position with respect to the - the role of it changes from a type being picked by the caller or callee. (If it's under an odd number of arrows the callee picks.) If you remove all the explicit type abstractions and applications above then you have Haskell (+ RankN). As other have pointed out, you can't remove the nested foralls because in general they cannot be inferred. Hope this helps. -- Lennart On Wed, May 28, 2008 at 7:51 PM, Andrew Coppin [EMAIL PROTECTED] wrote: Luke Palmer wrote: When you're reasoning about this, I think it would help you greatly to explicitly put in *all* the foralls. In haskell, when you write, say: map :: (a - b) - [a] - [b] All the free variables are *implicitly* quantified at the top level. That is, when you write the above, the compiler sees: map :: forall a b. (a - b) - [a] - [b] And the type you mention above for the strange expression is: forall x. (x - x) - (Char, Bool) Which indicates that the caller gets to choose. That is, if a caller sees a 'forall' at the top level, it is allowed to instantiate it with whatever type it likes. Whereas the type you want has the forall in a different place than the implicit quantifiaction: (forall x. x - x) - (Char, Bool) Here the caller does not have a forall at the top level, it is hidden inside a function type so the caller cannot instantiate the type. However, when implementing this function, the argument will now have type forall x. x - x And the implementation can instantiate x to be whatever type it likes. Hmm. Right. So you're saying that the exact position of the forall indicates the exact time when the variable(s) get specific types assigned to them? So... the deeper you nest the foralls, the longer those variables stay unbound? [And the higher the rank of the type?] Finally, that seems to make actual sense. I have one final question though: forall x, y. x - y - Z forall x. x - (forall y. y - Z) Are these two types the same or different? [Ignoring for a moment the obvious fact that you'll have one hell of a job writing a total function with such a type!] After all, ignoring the quantification, we have x - y - Z x - (y - Z) which are both the same type. So does that mean you can move the forall to the left but not to the right? Or are the types actually different? ___ 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
Re: [Haskell-cafe] Re: Aren't type system extensions fun? [Further insight]
On 5/28/08, Isaac Dupree [EMAIL PROTECTED] wrote: Andrew Coppin wrote: Finally, that seems to make actual sense. I have one final question though: forall x, y. x - y - Z forall x. x - (forall y. y - Z) Are these two types the same or different? [Ignoring for a moment the obvious fact that you'll have one hell of a job writing a total function with such a type!] they're the same type: foralls in function *results* can be moved to the outside with no change in meaning. They don't make it a higher rank type. (though some definitions in typically-uncurried languages like to call it higher rank, that's not relevant to us). (modulo GHC issues with impredicative polymorphism, which ideally shouldn't even come into the picture here, because you're only using/exploring RankNTypes) To be clear, these types are different but it doesn't matter because we are also given a type-abstraction rule which allows us to convert between the two trivially. For example, given: const :: forall a b. a - b - a const2 :: forall a. a - (forall b. b - a) When you partially apply const, you need to specify a type for the second argument (see the previous person talking about locking down type variables at the call site). However, you don't know what type to lock down b to, so you can let your caller choose! Here's an example... test = const (1 :: Int) What is the type of test? First we need to lock down the types for const; part of that involves generating a type variable for the a and b arguments for const; while the a argument unifies with Int, it turns out the b type variable is never used, so we allow the user to choose it, ending up with the result: test :: forall b. b - Int The reason why you can always move a forall to the left of a function arrow is very simple; given a type A (that may have some type variables, but no bs.), and a type B (that may have some type variables, including b), consider these two types: type t1 = forall b. (A - B) type t2 = A - (forall b. B) To convert from t1 to t2, since A has no mention of the type variable b, we just delay the decision of what b should be. In system F notation, given an expression e1 of type t1, we can convert it to t2 in the following way: ] e2 :: t2 ] e2 = \(a :: A) - /\ b - e1 @b a Similarily, given an expression e2 of type t2, we can convert to t1: ] e1 :: t1 ] e1 = /\ b - \(a :: A) - e2 a b However, if we have a higher ranked type: type t3 = (forall b. B) - A type t4 = forall b. (B - A) this conversion no longer works! This is because expressions of type t3 may call their arguments at many instances of b. We can, however, convert an expression e4 of type t4 into the higher-ranked type t3: ] e3 :: t3 ] e3 = \(x :: forall b. B) - e4 @Int (x @Int) Notice that we had to choose some arbitrary type (I picked Int) to instantiate x at when calling e4; this shows that the rank-2 type is definitely different than the rank-1 type; it leaves more choices up to the callee! -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ambiguous constraint errors
I have two related questions: #1 I'm getting some annoying type errors that I don't fully understand, and wind up having to do a workaround that I don't totally like. Here's a simplified version of my situation: data Ambi m = Ambi { ambi_monad :: m Int , ambi_int :: Int } some_ambi :: Monad m = Ambi m some_ambi = Ambi (return 5) 10 ambi_table :: Monad m = [(String, Ambi m)] ambi_table = [(default, some_ambi)] get_int :: String - Maybe Int get_int sym = fmap ambi_int (lookup sym ambi_table) --- get_int produces: Ambiguous type variable `m' in the constraint: `Monad m' arising from a use of `ambi_table' at ambi.hs:13:40-49 So I guess this means I'm not telling it which 'm', so it doesn't know how to resolve the 'return'... but the thing is, I'm not even using that value, so it doesn't matter what it resolves to. So it works if I pick some random monad: get_int sym = fmap ambi_int (lookup sym ambi_table :: Maybe (Ambi Maybe)) Note that I can't leave it as 'Monad m = Ambi m' because I still get an ambiguous type variable complaint. I'm a little disconcerted by having to pick some random dummy monad. Even worse, everything this type touches starts requiring explicit type declarations everywhere. Is there some easier way to do this? #2 This is somewhat related to another issue I've been having, which is that I have some kind of complicated type, e.g. '(SomeMonad some, Monad m) = some (SomethingM m Status)' that I use in a lot of places. It would be a lot less typing and easier to modify later if I wrote a type alias: type Command = (Monad some, Monad m) = some (State.StateT () m Status) but of course, this isn't allowed, since the type variables don't appear on the lhs, and if I put a context there, it's a syntax error. While I can write it with data: data (Monad some, Monad m) = Command some m = Command (some (State.StateT () m Status)) I've been told this doesn't mean what I expect it to, which is that the context constraints propagate up to and unify with the containing type (out of curiosity, since it's accepted, what *does* this do? I think I read it somewhere once, but now I forget and can't find it). And sure enough, using this type doesn't make my type declarations have the right contexts. So the first problem means that I have to declare types in various inconvenient places, and the second one means that I have to type out all the various class constraints (I can still alias away the non-polymorphic bits), and all my type declarations start looking much more complicated than they are. The solution I've been using for some of this is just to remove the polymorphism, so I can write a simple alias like type Command = SomethingM (State.StateT () Identity Status) and now I can think of a command and have various functions that take and return Commands, without caring that it's some kind of monad with context constraints. But of course, this isn't always possible since sometimes I need the type to remain polymorphic (i.e. while most of these I don't *think* will run in some other monad, some of them definitely get called in multiple contexts). Is there any nicer way around this? And what's the underlying issue that makes this necessary? I can live with all the context hair everywhere, but it sure would be nicer to be able to define it once and for all in one place. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] So how do people pronounce 'cabal' around here?
On 28 May 2008, at 1:04 pm, Dan Piponi wrote: In particular, which syllable gets the stress, and what are the lengths of the two vowels? Couldn't find anything in the FAQ (http://www.haskell.org/haskellwiki/Cabal/FAQ). I've always pronounced it k'BAHL, but was surprised to find that the OED (http://dictionary.oed.com/cgi/entry/50030715? query_type=wordqueryword=cabalfirst=1max_to_show=10 sort_type=alpharesult_place=1search_id=XrC0- le6sHc-11893hilite=50030715) only countenances a short second syllable: (kinline: schwa.gifinline: sm.gif bæl) [a. F. cabale (16th c. in Littré), used in all the English senses, ad. med.L. cab(b)ala (It., Sp., Pg. cabala), CABBALA, q.v. In 17th c. at first pronounced inline: sm.gif cabal (whence the abridged CAB n.5); the current pronunciation was evidently reintroduced from Fr., perh. with sense 5 or 6.] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] is there some book about haskell and data struct and alg?
Although all the source code for the pdf version (http://www.cs.cmu.edu/~rwh/theses/okasaki.pdf) of Purely Functional Data Structures is provided in Standard ML, not Haskell, I found a broken link to the supposedly equivalent Haskell source code on Books - HaskellWiki (http://haskell.org/haskellwiki/Books): Haskell source code for the book: http://www.cs.columbia.edu/~cdo/pfds-haskell.tar.gz Clicking on this link results in the following error: -- File Not Found The requested URL was not found on this web server: /~cdo/pfds-haskell.tar.gz You followed a link from http://haskell.org/haskellwiki/Books Contact the maintainer: [no address given]. Other solutions: * You may find what you need by performing a search in the main index for this web site. * You can perform a Google search on the departmental pages. This Columbia University Computer Science web server, www.cs.columbia.edu, is maintained by [no address given] -- Without the equivalent Haskell source code, the code must be manually translated from Standard ML into Haskell. Does anybody know why the link is broken, when it may be fixed, and from where the Haskell source code can be currently obtained? Benjamin L. Russell --- On Thu, 5/29/08, Loup Vaillant [EMAIL PROTECTED] wrote: 2008/5/28 Iavor Diatchki [EMAIL PROTECTED]: Hi, Purely Functional Data Structures by Chris Okasaki is a good one. Here is a link to it on Amazon: http://www.amazon.com/Purely-Functional-Structures-Chris-Okasaki/dp/0521663504 Good luck! -Iavor Argh, I'm predated by a few seconds! :-) Before buying the book (I did), you may want to check the slightly different pdf: http://www.cs.cmu.edu/~rwh/theses/okasaki.pdf 2008/5/28 smellcode [EMAIL PROTECTED]: is there some book about haskell and data struct and alg? i mean data struct and algorithm in haskell i am freshman i want to study haskell with data struct and alg -- Hu Jinpu (nickname: smellcode) Web developer email =~ /(^hujinpu)\@(gmail)\.(com)$/ or email.gsub!(/hujinpu/, 'smellcode') http://hujinpu.net ___ 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 ___ 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
[Haskell-cafe] type-level integers using type families
Has anyone else tried implementing type-level integers using type families? I tried using a couple of other type level arithmetic libraries (including type-level on Hackage) and they felt a bit clumsy to use. I started looking at type families and realized I could pretty much build an entire Scheme-like language based on them. In short, I've got addition, subtraction, multiplication working after just a days worth of hacking. I'm going to post the darcs archive sometime, sooner if anyone's interested. I really like the type-families based approach to this, it's a lot easier to understand, and you can think about things functionally instead of relationally. (Switching back and forth between Prolog-ish thinking and Haskell gets old quick.) Plus you can do type arithmetic directly in place, instead of using type classes everywhere. One thing that I'd like to be able to do is lazy unification on type instances, so that things like data True data False type family Cond x y z type instance Cond True y z = y type instance Cond False y z = z will work if the non-taken branch can't be unified with anything. Is this planned? Is it even feasible? I'm pretty sure it would be possible to implement a Lambda like this, but I'm not seeing it yet. Any ideas? Pete ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe