Re: [Haskell-cafe] data type declaration

2010-07-25 Thread Andrew Coppin
Patrick Browne wrote: Hi, I am trying to understand the data type declaration below. What is the relation between class C3 and the data type Address below? Where is such a technique used? OK, let's see what we can come up with... module A where data Person = Person String Integer deriving

Re: [Haskell-cafe] Type problems

2010-07-25 Thread Andrew Coppin
Ivan Miljenovic wrote: On 25 July 2010 05:50, Tobias Brandt tob.bra...@googlemail.com wrote: You have to fix the type of 1 and 6, e.g. by writing x - randomRIO (1, 6) :: IO Int or x - randomRIO (1, 6 :: Int) GHCi defaults integral numbers to Int, that's why it works there. The

Re: [Haskell-cafe] Type problems

2010-07-25 Thread Daniel Fischer
On Sunday 25 July 2010 14:12:03, Andrew Coppin wrote: Ivan Miljenovic wrote: On 25 July 2010 05:50, Tobias Brandt tob.bra...@googlemail.com wrote: You have to fix the type of 1 and 6, e.g. by writing x - randomRIO (1, 6) :: IO Int or x - randomRIO (1, 6 :: Int) GHCi defaults integral

Re: [Haskell-cafe] Type problems

2010-07-25 Thread Andrew Coppin
Daniel Fischer wrote: On Sunday 25 July 2010 14:12:03, Andrew Coppin wrote: Isn't there a default declaration where you can specify type defaulting? Yes, you can have one default declaration per module. Not a feature I ever use. I just vaguely remembered reading about it

Re: [Haskell-cafe] Type problems

2010-07-25 Thread Daniel Fischer
On Sunday 25 July 2010 14:47:41, Andrew Coppin wrote: Daniel Fischer wrote: On Sunday 25 July 2010 14:12:03, Andrew Coppin wrote: Isn't there a default declaration where you can specify type defaulting? Yes, you can have one default declaration per module. Not a feature I ever use. I

Re: [Haskell-cafe] data type declaration

2010-07-25 Thread Stephen Tetley
On 25 July 2010 13:09, Andrew Coppin andrewcop...@btinternet.com wrote: This is not valid in Haskell '98. This is actually a type system extension known as multi-parameter type classes, which do not even vaguely correspond to anything in normal OOP. (Except for being very slightly similar to

Re: [Haskell-cafe] default function definitions

2010-07-25 Thread Malcolm Wallace
-- Is it true that instances must exists before we can run function or make subclasses? instance C1 Person where instance C1 Employee where You can *call* class methods only for types which are instances of that class. But you can certain *write* functions that make use of the class

Re: [Haskell-cafe] data type declaration

2010-07-25 Thread Patrick Browne
Andrew, Thanks for your detailed feedback, it is a great help. I appreciate that the code does not do anything useful, nor is it an appropriate way to write Haskell, but it does help me understand language constructs. I have seen statements like data C3 c3 a = Address c3 a = Address c3 a and

Re[Haskell-cafe] ad large file and match lines to a pattern

2010-07-25 Thread grzyb
Hi, I'm a beginner in haskell, I was trying to write the following code, but I still encourage some problems, can you help me with that? I need to read a large file and try to match each line to a pattern which is int,int value=string for example: 0,1 value=string1 1,5 value=string2 when the

Re: [Haskell-cafe] data type declaration

2010-07-25 Thread Andrew Coppin
Patrick Browne wrote: Andrew, Thanks for your detailed feedback, it is a great help. Well, I like to be helpful. I appreciate that the code does not do anything useful, nor is it an appropriate way to write Haskell, but it does help me understand language constructs. Personally, I find

Re: [Haskell-cafe] data type declaration

2010-07-25 Thread Vo Minh Thu
2010/7/25 Andrew Coppin andrewcop...@btinternet.com: Patrick Browne wrote: Andrew, Thanks for your detailed feedback, it is a great help. Well, I like to be helpful. I appreciate that the code does not do anything useful, nor is it an appropriate way to write Haskell, but it does help me

[Haskell-cafe] Yet another monad transformer or silly usage of Either?

2010-07-25 Thread Eugeny N Dzhurinsky
Hello, everybody! I am trying to develop some sort of library, which supposed to sign into a WEB service, then perform some requests with it. Initially I designed methods in the following way data DServError = InvalidCredentials | InvalidRequest | ... newtype Result a = Result { getOpResult ::

[Haskell-cafe] Random this! ;-)

2010-07-25 Thread michael rice
Hi All, From: http://en.wikibooks.org/wiki/Haskell/Understanding_monads/State    Exercises    1. Implement a function rollNDiceIO :: Int - IO [Int] that,   given an integer, returns a list with that number of pseudo-   random integers between 1 and 6. After a

Re: [Haskell-cafe] Random this! ;-)

2010-07-25 Thread Max Rabkin
On Sun, Jul 25, 2010 at 5:39 PM, michael rice nowg...@yahoo.com wrote: I know, ugly, but at least I got it to work. What's a better way to generate this list? rollNDiceIO n = sequence . replicate n $ randomRIO (1,6) {{ sequence . replicate n = replicateM n }} = replicateM n $ randomRIO

Re: [Haskell-cafe] Random this! ;-)

2010-07-25 Thread Tobias Brandt
Look for the function replicateM in the module Control.Monad. On 25 July 2010 17:39, michael rice nowg...@yahoo.com wrote: Hi All, From: http://en.wikibooks.org/wiki/Haskell/Understanding_monads/State Exercises 1. Implement a function rollNDiceIO :: Int - IO

Re: [Haskell-cafe] Random this! ;-)

2010-07-25 Thread michael rice
Hi Max, Wow! I tried both *sequence* and *replicate* but guess I didn't put them together properly. I didn't even know there was a *replicateM*. Much cleaner. Thanks Michael --- On Sun, 7/25/10, Max Rabkin max.rab...@gmail.com wrote: From: Max Rabkin max.rab...@gmail.com Subject: Re:

Re: [Haskell-cafe] data type declaration

2010-07-25 Thread Andrew Coppin
Vo Minh Thu wrote: 2010/7/25 Andrew Coppin andrewcop...@btinternet.com: Since you're interested in comparisons... A method is simply a way of giving the same name to several different functions, and have the compiler pick the correct one based on the argument types. [snip] Actually in

Re: [Haskell-cafe] Yet another monad transformer or silly usage of Either?

2010-07-25 Thread Job Vranish
Yeah, ErrorT should do what you want (EitherT is probably essentially the same thing) login would have the type: login :: String - String - ErrorT DServError IO LoginResponse and you would use it like this: result - runErrorT $ authenticatedReq You can use runErrorT, or catch when you want to

Re: [Haskell-cafe] Yet another monad transformer or silly usage of Either?

2010-07-25 Thread David Menendez
2010/7/25 Eugeny N Dzhurinsky b...@redwerk.com: Hello, everybody! I am trying to develop some sort of library, which supposed to sign into a WEB service, then perform some requests with it. Initially I designed methods in the following way data DServError = InvalidCredentials |

Re: [Haskell-cafe] Random this! ;-)

2010-07-25 Thread Ozgur Akgun
Sorry but I'll just go ahead and eta reduce it :) rollNDiceIO = flip replicateM $ randomRIO (1,6) On 25 July 2010 16:44, Max Rabkin max.rab...@gmail.com wrote: On Sun, Jul 25, 2010 at 5:39 PM, michael rice nowg...@yahoo.com wrote: I know, ugly, but at least I got it to work. What's a

Re: [Haskell-cafe] Random this! ;-)

2010-07-25 Thread michael rice
Cool. Everything's there but the N. Learning Haskell is a lot like learning to dance. Michael --- On Sun, 7/25/10, Ozgur Akgun ozgurak...@gmail.com wrote: From: Ozgur Akgun ozgurak...@gmail.com Subject: Re: [Haskell-cafe] Random this! ;-) To: Max Rabkin max.rab...@gmail.com Cc: michael rice

[Haskell-cafe] How to do this with associated types?

2010-07-25 Thread Alexey Karakulov
Suppose I have one piece of code like this: class Result r e | r - e where   failure :: e - r a     success :: a - r a at :: Result r String = [a] - Int - r a at xs i = if i = 0 i length xs     then success (xs !! i)     else failure Wrong index Either instance of

[Haskell-cafe] Actors and message-passing a la Erlang

2010-07-25 Thread Yves Parès
Hello ! I've been studying Erlang and Scala, and I was wondering if someone has already implemented an actors and message passing framework for concurrent and distributed programs in Haskell. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

[Haskell-cafe] Is 'flip' really necessary?

2010-07-25 Thread aditya siram
Eta-reducing is nice, and sometimes it makes code more readable. But 'flip' is one of those functions that always seems to hinder rather than help readability, conversely factoring out flip always makes code easier to comprehend. I don't see a need for its existence - maybe I'm missing something

Re: [Haskell-cafe] Is 'flip' really necessary?

2010-07-25 Thread Antoine Latter
On Sun, Jul 25, 2010 at 4:13 PM, aditya siram aditya.si...@gmail.com wrote: Eta-reducing is nice, and sometimes it makes code more readable. But 'flip' is one of those functions that always seems to hinder rather than help readability, conversely factoring out flip always makes code easier to

Re: [Haskell-cafe] Is 'flip' really necessary?

2010-07-25 Thread Daniel Fischer
On Sunday 25 July 2010 23:13:16, aditya siram wrote: Eta-reducing is nice, and sometimes it makes code more readable. But 'flip' is one of those functions that always seems to hinder rather than help readability, conversely factoring out flip always makes code easier to comprehend. I don't see

Re: [Haskell-cafe] How to do this with associated types?

2010-07-25 Thread Christopher Lane Hinson
But what to do with Maybe? instance Result Maybe where type Failure Maybe = forall e. e -- can't do this failure _ = Nothing success x = Just x Normally, I would use: type Failure Maybe = () Unless the ability to discard information of any type is somehow a salient feature.

Re: [Haskell-cafe] Is 'flip' really necessary?

2010-07-25 Thread Edward Z. Yang
Excerpts from aditya siram's message of Sun Jul 25 17:13:16 -0400 2010: Eta-reducing is nice, and sometimes it makes code more readable. But 'flip' is one of those functions that always seems to hinder rather than help readability, conversely factoring out flip always makes code easier to

Re: [Haskell-cafe] Actors and message-passing a la Erlang

2010-07-25 Thread Stephen Tetley
Volker Stolz and Frank Huch implemented Erlang style distribution/concurrency for Haskell quite a while ago - a search should turn up the relevant papers, the code might have disappeared. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

[Haskell-cafe] hGetContents: resource exhausted

2010-07-25 Thread Lally Singh
Hey all, This is on OpenSolaris. Simple attempts to build cabal packages give me this error, and I don't know what it means. Here's an example: [07/25 18:51::la...@sol type-level]$ runghc Setup.hs configure Configuring type-level-0.2.4... Setup.hs: fd:8: hGetContents: resource exhausted

Re: [Haskell-cafe] Actors and message-passing a la Erlang

2010-07-25 Thread Bernie Pope
On 26 July 2010 06:55, Yves Parès limestr...@gmail.com wrote: I've been studying Erlang and Scala, and I was wondering if someone has already implemented an actors and message passing framework for concurrent and distributed programs in Haskell. I've recently been working on MPI bindings for

Re: [Haskell-cafe] data type declaration

2010-07-25 Thread John Lato
From: Patrick Browne patrick.bro...@dit.ie Andrew, Thanks for your detailed feedback, it is a great help. I appreciate that the code does not do anything useful, nor is it an appropriate way to write Haskell, but it does help me understand language constructs. I have seen statements like

[Haskell-cafe] Techniques for ensuring parser correctness?

2010-07-25 Thread Jason Dagit
Hello, I find that parser correctness is often hard to verify. Therefore, I'm interested in techniques that others have used successfully, especially with Haskell. Techniques I'm aware of: * Round trip checks: Generate a datastructure, render as a string, parse back, and compare. Quickcheck

Re: Re[Haskell-cafe] ad large file and match lines to a pattern

2010-07-25 Thread Ivan Miljenovic
On 26 July 2010 00:48, grzyb zbigniew.grzy...@gmail.com wrote: Hi, I'm a beginner in haskell, I was trying to write the following code, but I still encourage some problems, can you help me with that? I need to read a large file and try to match each line to a pattern which is int,int

Re: [Haskell-cafe] data type declaration

2010-07-25 Thread Richard O'Keefe
On Jul 26, 2010, at 12:35 PM, John Lato wrote: Incidentally, there seems to be a consensus that this a Bad Idea [1]. Even when you specify a type class context on a data declaration, Haskell still requires you to specify the context on functions that use that data (Address c a). This has

[Haskell-cafe] Iteratee package: combining enumerators

2010-07-25 Thread Max Cantor
I have a series of files with binary encoded data in them, and want to create an enumerator iterates on the first element at the front of all the files. Something like the pseudocode: return . minimum = mapM (fmap (heads . lines) readFile) listOfFileNames I can use convStream to create an