Re: [Haskell-cafe] type variable in class instance

2012-09-11 Thread oleg
Corentin Dupon wrote about essentially the read-show problem: class (Typeable e) = Event e data Player = Player Int deriving (Typeable) data Message m = Message String deriving (Typeable) instance Event Player instance (Typeable m) = Event (Message m) viewEvent ::

[Haskell-cafe] ANNOUNCE: hsqml-0.1.1 (and hsqml-morris-0.1.0)

2012-09-11 Thread Robin KAY
Dear All, I would like to announce a new package called 'hsqml' [1]. HsQML provides a Haskell binding to the Qt Quick framework. It allows you to write graphical applications where the front-end is written in Qt Quick's QML language (incorporating JavaScript) and the back-end is written in

Re: [Haskell-cafe] Destructive updates to plain ADTs

2012-09-11 Thread Milan Straka
Hi, is there any way to perform a destructive update on a plain ADT? Hi Milan, perhaps this is a dumb question, but given that you're using a lazy functional language: why do you want to do destructive updates at all? Perhaps you'd be better off using an imperative/object-oriented

Re: [Haskell-cafe] type variable in class instance

2012-09-11 Thread Martijn Schrage
On 11-09-12 08:53, o...@okmij.org wrote: Corentin Dupon wrote about essentially the read-show problem: class (Typeable e) = Event e data Player = Player Int deriving (Typeable) data Message m = Message String deriving (Typeable) instance Event Player instance (Typeable m) =

Re: [Haskell-cafe] type variable in class instance

2012-09-11 Thread Corentin Dupont
Thanks Martijn, Oleg and Ryan for your kind replies! @Ryan and Martijn: I considered putting the viewEvent in the typeclass, but I figured out that would break the separation of concerns. Indeed this typeclass Event belongs to the inner engine, while the display is done in another component (not

Re: [Haskell-cafe] type variable in class instance

2012-09-11 Thread Sean Leather
On Tue, Sep 11, 2012 at 3:39 PM, Corentin Dupontwrote: @Oleg: Yes the set of events is closed and I would be much happier with a GADT! But no matter how hard I tried I couldn't manage. Here is the full problem: *{-# LANGUAGE ExistentialQuantification, TypeFamilies, DeriveDataTypeable #-}

Re: [Haskell-cafe] type variable in class instance

2012-09-11 Thread Corentin Dupont
Yes. That's fantastic! This GADT is the missing piece of my puzzle. I transformed a bit your solution, polluting it with some classes instances and fleshing the functions: *data Player = Arrive | Leave deriving (Show, Typeable, Eq) data Message m = Message String deriving (Show, Typeable, Eq)

Re: [Haskell-cafe] type variable in class instance

2012-09-11 Thread Corentin Dupont
I finally come up with this version, which allows to do pattern matching against the events. I'm sure it could be cleaned a bit, but it think the idea is there. I would like to thank again everybody on this list, that's very friendly and helpful! Corentin *{-# LANGUAGE ExistentialQuantification,

[Haskell-cafe] Either Monad and Laziness

2012-09-11 Thread Eric Velten de Melo
Hello, I am currently trying to rewrite the Graphics.Pgm library from hackage to parse the PGM to a lazy array. The current implementation parses it straight to UArray, which is strict. The behaviour I want to achieve is like this: I want the program when compiled to read from a file, parsing

[Haskell-cafe] Pattern matching: multi constructors to same branch

2012-09-11 Thread Thiago Negri
Is it possible to capture more than one constructor in a single pattern matching? I mean, is it possible to generalize the following pattern matching of A and B to a single branch? g f C = [f C] g f v@(A _ n) = f v : g n g f v@(B _ n) = f v : g n For example: g f C = [f C] g f v@(A|B _ n) = f v

Re: [Haskell-cafe] type variable in class instance

2012-09-11 Thread David Menendez
I'm not sure I understand On Tue, Sep 11, 2012 at 11:06 AM, Corentin Dupont corentin.dup...@gmail.com wrote: Yes. That's fantastic! This GADT is the missing piece of my puzzle. I transformed a bit your solution, polluting it with some classes instances and fleshing the functions: data

Re: [Haskell-cafe] type variable in class instance

2012-09-11 Thread Corentin Dupont
Hi David, that may be also a way to go. I've also looked into this way (view patterns), unfortunately it seems that I will be obliged to maintain 2 parallel structures: for each Event instance, I will have to add a ViewEvent element as well carrying the same information: instance Event Time where

Re: [Haskell-cafe] type variable in class instance

2012-09-11 Thread Sean Leather
On Tue, Sep 11, 2012 at 6:46 PM, David Menendez wrote: Mixing GADTs and Typeable seems like a bad idea. If you really don't want to put viewEvent in the Event typeclass, but the class of events is closed, you could use a GADT to witness the event type. On Tue, Sep 11, 2012 at 7:03 PM,

Re: [Haskell-cafe] Either Monad and Laziness

2012-09-11 Thread Evan Laforge
On Tue, Sep 11, 2012 at 9:36 AM, Eric Velten de Melo ericvm...@gmail.com wrote: Any thoughts? Hopefully I'm not saying anything really stupid. You can intersperse decoding errors in the output, e.g. output is [Either Error DecodedChunk]. Then all the processors have to deal with it, but if you

Re: [Haskell-cafe] type variable in class instance

2012-09-11 Thread Corentin Dupont
That's very interesting. One problem is, if the set of event is closed, the set of possible data types is not (the user can choose any data type for a Message callback for example). I think this can be solved using a class instead of a GADT for Type. One can also use a type witness? On Tue, Sep

Re: [Haskell-cafe] Either Monad and Laziness

2012-09-11 Thread timothyhobbs
Use a tuple: (Result,Maybe Error) rather than an Either.  Do everything lazily, and in the case of an error, undo the result. -- Původní zpráva -- Od: Eric Velten de Melo ericvm...@gmail.com Datum: 11. 9. 2012 Předmět: [Haskell-cafe] Either Monad and Laziness Hello, I am

Re: [Haskell-cafe] type variable in class instance

2012-09-11 Thread Sean Leather
On Tue, Sep 11, 2012 at 9:18 PM, Corentin Dupont wrote: That's very interesting. One problem is, if the set of event is closed, the set of possible data types is not (the user can choose any data type for a Message callback for example). I think this can be solved using a class instead of a

Re: [Haskell-cafe] Pattern matching: multi constructors to same branch

2012-09-11 Thread Michael Sloan
I've seen this asked before, and I think some languages support it (ML maybe?). One way to do this is with view patterns: g f C = [f C] g f (getVN - (v, n)) = f v : g f n getVN v@(A _ n) = (v, n) getVN v@(B _ n) = (v, n) (I changed the recursive call to g - figured you meant passing along f)

Re: [Haskell-cafe] type variable in class instance

2012-09-11 Thread oleg
Let me see if I understand. You have events of different sorts: events about players, events about timeouts, events about various messages. Associated with each sort of event is a (potentially open) set of data types: messages can carry payload of various types. A handler specifies behavior of a