[Haskell-cafe] Real World Haskell Chapter 19 and GHC 6.10

2009-10-21 Thread Michael Mossey
The examples in the "error handling" chapter (19) of RWH don't run under GHC 6.10. For instance, an example might be main = handle (\_ -> putStrLn "error") (print $ 5 `div` 0) Trying to load this results in "amigous type variable 'e' in the constraint: 'Exception e' arising from a use of 'han

Re: [Haskell-cafe] Real World Haskell Chapter 19 and GHC 6.10

2009-10-21 Thread Luke Palmer
On Wed, Oct 21, 2009 at 3:29 AM, Michael Mossey wrote: > The examples in the "error handling" chapter (19) of RWH don't run under GHC > 6.10. > > For instance, an example might be > > main = handle (\_ -> putStrLn "error") (print $ 5 `div` 0) > > Trying to load this results in "amigous type variab

Re: [Haskell-cafe] Test cases for type inference

2009-10-21 Thread Martijn van Steenbergen
Peter Verswyvelen wrote: For learning, I would like to develop my own implementation of type inference, based on the paper "Typing Haskell in Haskell". At first sight, the source code of THIH contains a small number of tests, but I was wandering if a large test set exist? I'm pretty sure GHC m

Re: [Haskell-cafe] Real World Haskell Chapter 19 and GHC 6.10

2009-10-21 Thread Gregory Collins
Michael Mossey writes: > The examples in the "error handling" chapter (19) of RWH don't run under GHC > 6.10. > > For instance, an example might be > > main = handle (\_ -> putStrLn "error") (print $ 5 `div` 0) I usually use: main = handle (\(_ :: SomeException) -> putStrLn "error") (print

Re: [Haskell-cafe] Real World Haskell Chapter 19 and GHC 6.10

2009-10-21 Thread Yusaku Hashimoto
To deal with "amigous type variable 'e'", I often write the codes like: handle (\...@someexception{} -> print e) (5 `div` 0) and IIRC, the base-4.0 initially released with GHC 6.10.1, introduced this exceptions. It enables us to specify which exception should be caught and define types of exc

Re: [Haskell-cafe] Test cases for type inference

2009-10-21 Thread Job Vranish
I was recently working on an type inference algorithm and to test it I did the following: Used the quickcheck Arbitrary typeclass to generate expressions Inferred types of the expressions using my algorithm, converted the expressions that passed inference to haskell and wrote them to a file (

Re: [Haskell-cafe] Real World Haskell Chapter 19 and GHC 6.10

2009-10-21 Thread Benjamin Herr
Hi, Excerpts from Michael Mossey's message of Mi Okt 21 11:29:53 +0200 2009: > how to get the RWH examples to run? Changing the imports from Control.Exception to Control.OldException did it for me. I am not sure whether this is what you were looking for, but it should at least allow you to follow

[Haskell-cafe] Re: systemtimmetypeable: Workaround for lack of deriveable data instance in either System.Time or Data.Time.

2009-10-21 Thread Thomas Hartman
update: on haskell reddit, dons suggested simply patching time. reasonable enough, but I hit a glitch where the Data.Fixed (in base lib) was missing a Data instance, and gave up when I couldn't find the source repo for base. Is this simply part of ghc? Anyways, that instance seems to be added in

Re: [Haskell-cafe] Real World Haskell Chapter 19 and GHC 6.10

2009-10-21 Thread David Leimbach
It's educational to port the examples yourself. Dave On Wed, Oct 21, 2009 at 8:56 AM, Benjamin Herr wrote: > Hi, > > Excerpts from Michael Mossey's message of Mi Okt 21 11:29:53 +0200 2009: > > how to get the RWH examples to run? > > Changing the imports from Control.Exception to Control.OldExce

[Haskell-cafe] Re: systemtimmetypeable: Workaround for lack of deriveable data instance in either System.Time or Data.Time.

2009-10-21 Thread Ashley Yakeley
Data.Fixed (in base) has been updated with Data instances in HEAD. When that's released, I'll release time-extra that will contain Data instances. I've got it all ready to go. The reason Data instances are in time-extras is that the time library must be Haskell 98, while Data instances require Ran

[Haskell-cafe] Simple but interesting (for me) problem

2009-10-21 Thread michael rice
There's a thread on the plt-scheme list about creating a function of NO arguments named NEXT that just returns the number of times it's been called, a piece of cake in Scheme, but how would one do this in Haskell? Would the best approach be to use a State monad? Michael

Re: [Haskell-cafe] Simple but interesting (for me) problem

2009-10-21 Thread Brent Yorgey
On Wed, Oct 21, 2009 at 10:34:47AM -0700, michael rice wrote: > There's a thread on the plt-scheme list about creating a function of NO > arguments named NEXT that just returns the number of times it's been called, > a piece of cake in Scheme, but how would one do this in Haskell? Would the > be

Re: [Haskell-cafe] Simple but interesting (for me) problem

2009-10-21 Thread minh thu
2009/10/21 michael rice > > There's a thread on the plt-scheme list about creating a function of NO > arguments named NEXT that just returns the number of times it's been called, > a piece of cake in Scheme, but how would one do this in Haskell? Would the > best approach be to use a State monad

Re: [Haskell-cafe] Simple but interesting (for me) problem

2009-10-21 Thread Tim Wawrzynczak
I'm guessing the function looks something like this? (this is common lisp not scheme) (let ((counter 0)) (defun next () (incf counter) counter)) So the first time you call (next), it returns 1, then 2, etc. The function (next) is a closure over the variable 'counter' and acts by increme

Re: [Haskell-cafe] Test cases for type inference

2009-10-21 Thread jur
On Tue, Oct 20, 2009 at 10:07 AM, Peter Verswyvelen wrote: For learning, I would like to develop my own implementation of type inference, based on the paper "Typing Haskell in Haskell". At first sight, the source code of THIH contains a small number of tests, but I was wandering if a large t

Re: [Haskell-cafe] Simple but interesting (for me) problem

2009-10-21 Thread Tim Wawrzynczak
Here's an example in the IO monad: import Data.IORef import System.IO.Unsafe counter = unsafePerformIO $ newIORef 0 next = do modifyIORef counter (+1) readIORef counter Naturally, this uses unsafePerformIO, which as you know, is not kosher... Cheers, - Tim On Wed, Oct 21, 2009 at 1:00 PM

Re: [Haskell-cafe] Simple but interesting (for me) problem

2009-10-21 Thread minh thu
2009/10/21 Tim Wawrzynczak > > Here's an example in the IO monad: > > import Data.IORef > import System.IO.Unsafe > > counter = unsafePerformIO $ newIORef 0 > > next = do > modifyIORef counter (+1) > readIORef counter > > Naturally, this uses unsafePerformIO, which as you know, is not kosher..

Re: [Haskell-cafe] Simple but interesting (for me) problem

2009-10-21 Thread Alex Queiroz
Hallo, On 10/21/09, Tim Wawrzynczak wrote: > Here's an example in the IO monad: > > import Data.IORef > import System.IO.Unsafe > > counter = unsafePerformIO $ newIORef 0 > > next = do > modifyIORef counter (+1) > readIORef counter > > Naturally, this uses unsafePerformIO, which as you know,

Re: [Haskell-cafe] Test cases for type inference

2009-10-21 Thread Peter Verswyvelen
Thanks Job & Martijn for the feedback. I would like to write a type inferrer that is mostly Haskell 98 with Trex row polymorphism extensions (a bit like CAL I guess). That will certainly take a while because I'm also studying the theory in my spare time. So as soon as (or if) I have something wo

[Haskell-cafe] Re: Simple but interesting (for me) problem

2009-10-21 Thread Neal Alexander
michael rice wrote: There's a thread on the plt-scheme list about creating a function of NO arguments named NEXT that just returns the number of times it's been called, a piece of cake in Scheme, but how would one do this in Haskell? Would the best approach be to use a State monad? Michael

Re: [Haskell-cafe] Simple but interesting (for me) problem

2009-10-21 Thread Tim Wawrzynczak
True...here we go then: import Data.IORef import System.IO.Unsafe mkNext :: (Num a) => IO (IO a) mkNext = do ref <- newIORef 0 return (do modifyIORef ref (+1) readIORef ref) next :: IO () next = do foo <- mkNext a <- sequence [foo,foo,foo] putStrLn $ show a running next

Re: [Haskell-cafe] Simple but interesting (for me) problem

2009-10-21 Thread Gregory Crosswhite
And just because this has not been explicitly stated: it's not just for aesthetic reasons that you couldn't do this with a pure function, but because it violates the semantics and gets you the wrong result. So for example, if you modified Tim's code to be import Data.IORef import System.

Re: [Haskell-cafe] Simple but interesting (for me) problem

2009-10-21 Thread minh thu
2009/10/21 Tim Wawrzynczak : > True...here we go then: > > import Data.IORef > import System.IO.Unsafe > > mkNext :: (Num a) => IO (IO a) > mkNext = do > ref <- newIORef 0 > return (do modifyIORef ref (+1) > readIORef ref) > > next :: IO () > next = do > foo <- mkNext > a <- se

Re: [Haskell-cafe] list -> sublists

2009-10-21 Thread Eduard Sergeev
satorisanitarium wrote: > > How to make a list of sublists out of a list, whether they be a list of > numbers or a string. > Without recursion (with fold) starting from the tail of the input list: foo n = foldr st [[]] where st x xss | x == n = [x]:xss st x (xs:xss) = (x:x

[Haskell-cafe] ANN: Data.Stream 0.4

2009-10-21 Thread Wouter Swierstra
I'm happy to announce a new release of the Data.Stream library. http://hackage.haskell.org/package/Stream The only change with the previous version has been to add irrefutable patterns to several function definitions. This is rather delicate design decision: too many irrefutable patterns c

Re: [Haskell-cafe] Re: Simple but interesting (for me) problem

2009-10-21 Thread michael rice
Thanks everyone, Hmm...I hadn't thought about it that way, but w/r/t Haskell you're absolutely right. People have said that Haskell is good to learn because it makes one think differently about programming, and they're right. Michael --- On Wed, 10/21/09, Neal Alexander wrote: From: Neal A

Re: [Haskell-cafe] How to use "bracket" properly ?

2009-10-21 Thread Henning Thielemann
zaxis schrieb: > winSSQ count noRed noBlue = do { > yesRed <- [1..33] \\ noRed; > yesBlue <- [1..16] \\ noBlue; > bracket (openFile "ssqNum.txt" WriteMode) (hClose) (\hd1 -> pickSSQ > count yesRed yesBlue hd1); > return () You might prefer 'withFile' or even better and if possible

[Haskell-cafe] ANN: GPipe 1.02 and Vec-Transform 1.0.1

2009-10-21 Thread Tobias Bexelius
I've uploaded new versions of these two packages to hackage: GPipe-1.0.2: * Removed rasterize and made rasterizeFront work for other primitives than triangles instead. * Fixed notB Vertex and Fragment instances Vec-Transform-1.0.1: * Added rotationLookAt Cheers Tobias Bexelius

[Haskell-cafe] Cabal says "no installed version of base"

2009-10-21 Thread John Velman
I'm on OS X Leopard 10.5.8, using ghc 6.10.4 from Haskell Platform. I'm trying to get a static .a library, callable from C, that I can use in an OS X Cocoa program. I've tried a very simple case (the one in Haskell Wiki Tutorials,"calling haskell from C") I've managed to make a Mac Cocoa applicat

[Haskell-cafe] Is there a null statement that does nothing?

2009-10-21 Thread michael rice
It looks like both the THEN and the ELSE in an IF expression must each have an expression. What's a graceful way to do nothing in either or both slots, kind of like the Fortran CONTINUE statement.   --mr [mich...@localhost ~]$ ghci GHCi, version 6.10.3: http://www.haskell.org/

Re: [Haskell-cafe] Is there a null statement that does nothing?

2009-10-21 Thread Thomas DuBuisson
If its monadic code then use Control.Monad.when. If its pure code then omitting the 'else' clause makes no sense what-so-ever; to omit the else you must know the boolean is always true so why have the if? See the "Common Misunderstandings" [1] page I put together in response to seeing one too man

Re: [Haskell-cafe] Is there a null statement that does nothing?

2009-10-21 Thread Tim Wawrzynczak
Yes, an if statement must have both 'then' and 'else' branches. As an example, what if you had let a = if b == 2 then True else False and you were missing an else branch? What would 'a' get assigned to? The if statement "returns" a value so must have both branches. However, in a monadic const

Re: [Haskell-cafe] Is there a null statement that does nothing?

2009-10-21 Thread michael rice
Thanks guys, I understand what you're telling me, but have some nested IFs and just want to fall through on one of the ELSES but then I end up with two ELSES in a row and nothing between them. Oh, well, on to restructuring. Michael --- On Wed, 10/21/09, Tim Wawrzynczak wrote: From: Tim Wawr

Re: [Haskell-cafe] Is there a null statement that does nothing?

2009-10-21 Thread Dan Weston
If you have a long if/else if/else chain, you might consider a trivial case statement with guards. Whether you think this is attractive is a matter of taste, but it has the fall-through semantics you want and ghc optimizes the _ pattern matching away: f x = case () of _| x == 2-> 22 _|

Re: [Haskell-cafe] Is there a null statement that does nothing?

2009-10-21 Thread michael rice
Those nested IF/THEN/ELSEs are real killers. I kind of use them to sort out my thoughts, then end up with a nested mess. The restructuring to WHENs went smoothly and looks a lot cleaner besides. Michael --- On Wed, 10/21/09, Dan Weston wrote: From: Dan Weston Subject: Re: [Haskell-cafe] Is t

[Haskell-cafe] Needing strictness?

2009-10-21 Thread michael rice
Busy night. I wanted the question and response to be on the same line (see below), so I used putStr instead of putStrLn, but Haskell jumps the gun and goes to the second line to get the response before the question ever gets printed. Is this an example of needing strictness? How would I do that,

Re: [Haskell-cafe] Needing strictness?

2009-10-21 Thread Johan Tibell
Hi Michael, I believe stdout uses line buffering by default so you need to explicitly flush the buffer to get the output -- Johan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Needing strictness?

2009-10-21 Thread michael rice
Hey Johan, And I can do that how? Michael --- On Wed, 10/21/09, Johan Tibell wrote: From: Johan Tibell Subject: Re: [Haskell-cafe] Needing strictness? To: "michael rice" Cc: haskell-cafe@haskell.org Date: Wednesday, October 21, 2009, 10:18 PM Hi Michael, I believe stdout uses line bufferin

Re: [Haskell-cafe] Needing strictness?

2009-10-21 Thread Daniel Fischer
Am Donnerstag 22 Oktober 2009 04:15:56 schrieb michael rice: > Busy night. I wanted the question and response to be on the same line (see > below), so I used putStr instead of putStrLn, but Haskell jumps the gun and > goes to the second line to get the response before the question ever gets > print

Re: [Haskell-cafe] Needing strictness?

2009-10-21 Thread Daniel Fischer
Am Donnerstag 22 Oktober 2009 04:15:56 schrieb michael rice: > Busy night. I wanted the question and response to be on the same line (see > below), so I used putStr instead of putStrLn, but Haskell jumps the gun and > goes to the second line to get the response before the question ever gets > print

Re: [Haskell-cafe] Needing strictness?

2009-10-21 Thread michael rice
Hi Daniel, The first fix wouldn't work, but the second one (hFlush) did. Thanks, Michael --- On Wed, 10/21/09, Daniel Fischer wrote: From: Daniel Fischer Subject: Re: [Haskell-cafe] Needing strictness? To: haskell-cafe@haskell.org Cc: "michael rice" Date: Wednesday, October 21, 2009, 10:27

[Haskell-cafe] Re: ghci can't find Paths_ module created by cabal

2009-10-21 Thread Thomas Hartman
from my bash hints file: thart...@ubuntu:~/haskellInstalls/gitit>thartman_ghci_with_data_files Loading a package with data files in ghci See http://neilmitchell.blogspot.com/2008/02/adding-data-files-using-cabal.html Snip: The above method works well after a program has been ins

[Haskell-cafe] ANN: mecha-0.0.0

2009-10-21 Thread Tom Hawkins
A few months ago, I started toying with a few alternative pump designs to power our hydraulic hybrids. After not being able to secure a ProE license, I searched for a free solid modeler to sketch out a few ideas. To my surprise, their are practically no open source 3D CAD packages available. So

[Haskell-cafe] why cannot i get the value of a IORef variable ?

2009-10-21 Thread zaxis
> let aaa = unsafePerformIO $ newIORef [] > writeIORef aaa [1,2,3] > readIORef aaa [(),(),()] sincerely! -- View this message in context: http://www.nabble.com/why-cannot-i-get-the-value-of-a-IORef-variable---tp26004111p26004111.html Sent from the Haskell - Haskell-Cafe mailing list archive at

Re: [Haskell-cafe] why cannot i get the value of a IORef variable ?

2009-10-21 Thread Kyle Murphy
I assume you're trying this at the GHCi prompt, which is where you're problem is coming from, specifically on the first line. When you do: > let aaa = unsafePerformIO $ newIORef [] GHCi takes a wild stab at the type of [] and comes up with the type [()], so now you have a IORef [()] type, which is

Re: [Haskell-cafe] Real World Haskell Chapter 19 and GHC 6.10

2009-10-21 Thread Michael Mossey
Apparently the old exception library had convenience functions like 'arithExceptions' that could be used with 'handleJust'. handleJust arithExceptions handler thing With the new module you can write something like this (I determined this from experimentation): arithExceptionTester :: ArithEx

Re: [Haskell-cafe] why cannot i get the value of a IORef variable ?

2009-10-21 Thread Thomas DuBuisson
zaxis wrote: >> let aaa = unsafePerformIO $ newIORef [] >> writeIORef aaa [1,2,3] >> readIORef aaa > [(),(),()] What in Haskells name do you think you're doing? Don't use unsafePerformIO like that! Its unnecessary and a bit concerning, really. Prelude> :m Data.IORef Prelude Data.IORef> x <- n

Re: [Haskell-cafe] why cannot i get the value of a IORef variable ?

2009-10-21 Thread zaxis
Yes, it works now! thank you very much! Kyle Murphy-2 wrote: > > I assume you're trying this at the GHCi prompt, which is where you're > problem is coming from, specifically on the first line. > When you do: >> let aaa = unsafePerformIO $ newIORef [] > GHCi takes a wild stab at the type of []

Re: [Haskell-cafe] why cannot i get the value of a IORef variable ?

2009-10-21 Thread zaxis
thank you! In fact i really donot understand "unsafePerformIO" very much ! Thomas DuBuisson wrote: > > zaxis wrote: >>> let aaa = unsafePerformIO $ newIORef [] >>> writeIORef aaa [1,2,3] >>> readIORef aaa >> [(),(),()] > > What in Haskells name do you think you're doing? Don't use > unsafeP

Re: [Haskell-cafe] why cannot i get the value of a IORef variable ?

2009-10-21 Thread Colin Paul Adams
zaxis> thank you! In fact i really donot understand zaxis> "unsafePerformIO" very much ! Then all you have to understand is - never use it! -- Colin Adams Preston Lancashire ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.has

Re: [Haskell-cafe] why cannot i get the value of a IORef variable ?

2009-10-21 Thread Gregory Crosswhite
For clarity, one trick that uses "unsafePerformIO" which you may have seen posted on this list earlier today is the following way of creating a globally visible IORef: import Data.IORef import System.IO.Unsafe *** counter = unsafePerformIO $ newIORef 0 *** next = do modifyIORef counter (+

Re: [Haskell-cafe] Time Typeable Instances

2009-10-21 Thread Warren Harris
Hi John, I just stumbled on this issue while trying to compile turbinado with the haskell platform / ghc 6.10.4. I got past it by manually editing back in the time definitions, but just wondering if there was an official resolution. Thanks, Warren On Oct 13, 2009, at 6:48 AM, John Goerz