Re: [Haskell-cafe] type class question

2009-09-30 Thread Henning Thielemann
Ben schrieb: dear haskellers -- i'm trying this question again, in haskell-cafe. i got some responses in haskell-beginners but am looking for more guidance. also, i understand this functionality is encapsulated in the Workflow module in hackage, but i'd like to understand this myself.

[Haskell-cafe] type class question

2009-09-29 Thread Ben
dear haskellers -- i'm trying this question again, in haskell-cafe. i got some responses in haskell-beginners but am looking for more guidance. also, i understand this functionality is encapsulated in the Workflow module in hackage, but i'd like to understand this myself. this email is an

Re: [Haskell-cafe] Re: type class question

2007-12-10 Thread Jules Bean
Try again without missing out the list... Peter Padawitz wrote: Jules Bean wrote: Incidentally, I question why the compFoo are methods. Why not just make them polymorphic functions? They don't look like you expect instances to change them. The code continues to compile if I make them

Re: [Haskell-cafe] Re: type class question

2007-12-10 Thread Peter Padawitz
Jules Bean wrote: Try again without missing out the list... Peter Padawitz wrote: Jules Bean wrote: Incidentally, I question why the compFoo are methods. Why not just make them polymorphic functions? They don't look like you expect instances to change them. The code continues to compile if

Re: [Haskell-cafe] Re: type class question

2007-12-10 Thread Jules Bean
Peter Padawitz wrote: What is so bad about making compFoo part of the class? It reduces the code (constraints can be avoided) and reflects the close connection between a signature Sig (implemented by the class) and the evaluation (compFoo) of Sig-terms in Sig-algebras. making it part of the

Re: [Haskell-cafe] Re: type class question

2007-12-10 Thread Jules Bean
Peter Padawitz wrote: Jules Bean wrote: Peter Padawitz wrote: What is so bad about making compFoo part of the class? It reduces the code (constraints can be avoided) and reflects the close connection between a signature Sig (implemented by the class) and the evaluation (compFoo) of

Re: [Haskell-cafe] Re: type class question

2007-12-10 Thread Peter Padawitz
Jules Bean wrote: Peter Padawitz wrote: Jules Bean wrote: Peter Padawitz wrote: What is so bad about making compFoo part of the class? It reduces the code (constraints can be avoided) and reflects the close connection between a signature Sig (implemented by the class) and the

Re: [Haskell-cafe] Re: type class question

2007-12-10 Thread Bertram Felgenhauer
Peter Padawitz wrote: Jules Bean wrote: I don't see why! In the class class Foo a where f :: a - Int g :: b - Integer g = fromIntegral . f The equations within the class are defaults, not equations. I must admit that I didn't know this... Nevertheless, won't you agree that

Re: [Haskell-cafe] Re: Re: type class question

2007-12-07 Thread Jules Bean
Peter Padawitz wrote: Functional dependencies don't work in my case. Actually, I don't see why they should. Ah well, it's cruel to say that without explaining to us why! I'm not sure why a complete cyclic dep a - b - c - d - a isn't what you want. What seems to be needed here is a type

Re: [Haskell-cafe] Re: Re: type class question

2007-12-07 Thread Peter Padawitz
Functional dependencies don't work in my case. Actually, I don't see why they should. What seems to be needed here is a type class construct with a kind of record parameter so that instance conflicts cannot occur. Jules Bean wrote: Ben Franksen wrote: Ryan Ingram wrote: On 12/5/07, Ben

Re: [Haskell-cafe] Re: Re: type class question

2007-12-07 Thread Jules Bean
Peter Padawitz wrote: Jules Bean wrote: Peter Padawitz wrote: Functional dependencies don't work in my case. Actually, I don't see why they should. Ah well, it's cruel to say that without explaining to us why! Cause I don't see why the instantiation conflicts pointed out by others

Re: [Haskell-cafe] Re: Re: type class question

2007-12-07 Thread Benja Fallenstein
On Dec 7, 2007 6:57 PM, Peter Padawitz [EMAIL PROTECTED] wrote: Jules Bean wrote: Peter Padawitz wrote: Cause I don't see why the instantiation conflicts pointed out by others would vanish then. They would. If it's really true that there is only one possible choice of b,c,d for

Re: [Haskell-cafe] Re: Re: type class question

2007-12-07 Thread Jules Bean
Peter Padawitz wrote: So the fundep would solve the problem. But, actually, it doesn't :-( But actually, it does! Ben Franksen's answer from yesterday compiles fine for me if I add the missing fundep, block - command. Your original code compiles without error, given the fundep. Exact

Re: [Haskell-cafe] Re: Re: type class question

2007-12-07 Thread Luke Palmer
On Dec 7, 2007 5:57 PM, Peter Padawitz [EMAIL PROTECTED] wrote: type Block = [Command] data Command = Skip | Assign String IntE | Cond BoolE Block Block | Loop BoolE Block data IntE= IntE Int | Var String | Sub IntE IntE | Sum [IntE] | Prod [IntE] data BoolE = BoolE Bool | Greater

Re: [Haskell-cafe] Re: Re: type class question

2007-12-07 Thread Peter Padawitz
Jules Bean wrote: Peter Padawitz wrote: Jules Bean wrote: Peter Padawitz wrote: Functional dependencies don't work in my case. Actually, I don't see why they should. Ah well, it's cruel to say that without explaining to us why! Cause I don't see why the instantiation conflicts

Re: [Haskell-cafe] Re: Re: type class question

2007-12-07 Thread Peter Padawitz
Jules Bean wrote: Peter Padawitz wrote: Functional dependencies don't work in my case. Actually, I don't see why they should. Ah well, it's cruel to say that without explaining to us why! Cause I don't see why the instantiation conflicts pointed out by others would vanish then. I'm

Re: [Haskell-cafe] type class question

2007-12-06 Thread Peter Padawitz
Yes, the recursive calls of compCommand are supposed to be calls of compBlock. The intention of the program is a generic evaluator comp... of Sigma-terms in arbitrary Sigma-algebras. The signature Sigma is given by the first 4 types (and the corresponding functions in the class declaration),

Re: [Haskell-cafe] type class question

2007-12-06 Thread Jules Bean
Peter Padawitz wrote: Yes, the recursive calls of compCommand are supposed to be calls of compBlock. The intention of the program is a generic evaluator comp... of Sigma-terms in arbitrary Sigma-algebras. The signature Sigma is given by the first 4 types (and the corresponding functions in

[Haskell-cafe] Re: Re: type class question

2007-12-06 Thread Ben Franksen
Ryan Ingram wrote: On 12/5/07, Ben Franksen [EMAIL PROTECTED] wrote: You would have to use functional dependencies or associated types to eliminate this error. Alternatively, you can add a dummy argument of type block and pass undefined :: BlockType in to help choose the instance

Re: [Haskell-cafe] Re: Re: type class question

2007-12-06 Thread Jules Bean
Ben Franksen wrote: Ryan Ingram wrote: On 12/5/07, Ben Franksen [EMAIL PROTECTED] wrote: You would have to use functional dependencies or associated types to eliminate this error. Alternatively, you can add a dummy argument of type block and pass undefined :: BlockType in to help choose the

Re: [Haskell-cafe] type class question

2007-12-05 Thread Brent Yorgey
On Dec 3, 2007 7:43 AM, Peter Padawitz [EMAIL PROTECTED] wrote: What is wrong here? ghci tries (and fails) to deduce certain types for the comp functions that I did not expect. type Block = [Command] data Command = Skip | Assign String IntE | Cond BoolE Block Block | Loop

[Haskell-cafe] Re: type class question

2007-12-05 Thread Ben Franksen
Brent Yorgey wrote: Well, first of all, the definition of compCommand should use calls to compBlock, not recursive calls to compCommand. But that's not the main source of your problems. What exactly are you trying to accomplish? And why do you need a type class? Whatever the code is

Re: [Haskell-cafe] Re: type class question

2007-12-05 Thread Felipe Lessa
On Dec 5, 2007 10:38 PM, Ben Franksen [EMAIL PROTECTED] wrote: data Command = Skip class Java block command where block_ :: [command] - block compBlock :: [Command] - block --compBlock = block_ . map compCommand compCommand :: Command - command My guess is that nothing's

Re: [Haskell-cafe] Re: type class question

2007-12-05 Thread Ryan Ingram
On 12/5/07, Ben Franksen [EMAIL PROTECTED] wrote: data Command = Skip class Java block command where block_ :: [command] - block compBlock :: [Command] - block --compBlock = block_ . map compCommand compCommand :: Command - command This compiles ok. But when I ask ghci for the type of

[Haskell-cafe] type class question

2007-12-03 Thread Peter Padawitz
What is wrong here? ghci tries (and fails) to deduce certain types for the comp functions that I did not expect. |type Block = [Command] data Command = Skip | Assign String IntE | Cond BoolE Block Block | Loop BoolE Block data IntE= IntE Int | Var String | Sub IntE IntE |

Re: [Haskell-cafe] type/class question: toString

2007-11-08 Thread Graham Fawcett
On Nov 7, 2007 4:34 PM, Nicholas Messenger [EMAIL PROTECTED] wrote: If you're willing to have an extra Typeable constraint, this does what you want: import Data.Typeable (Typeable, cast) import Data.Maybe (fromMaybe) toString :: (Show a, Typeable a) = a - String toString x =

Re: [Haskell-cafe] type/class question: toString

2007-11-07 Thread Nicholas Messenger
If you're willing to have an extra Typeable constraint, this does what you want: import Data.Typeable (Typeable, cast) import Data.Maybe (fromMaybe) toString :: (Show a, Typeable a) = a - String toString x = fromMaybe (show x) (cast x) *Main toString blah blah *Main toString 1 1 *Main

[Haskell-cafe] type/class question: toString

2007-11-06 Thread Graham Fawcett
Hi folks, Is there a way to declare a 'toString' function, such that toString x | x is a String = x toString x | x's type is an instance of Show = show x Perhaps, in the type system, there's a way to declare a ToString class, and somehow inherit all instances of Show as ToString instances?

RE: [Haskell-cafe] type/class question: toString

2007-11-06 Thread Bayley, Alistair
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Graham Fawcett Is there a way to declare a 'toString' function, such that toString x | x is a String = x toString x | x's type is an instance of Show = show x Perhaps, in the type system, there's a way to declare a

Re: [Haskell-cafe] type/class question: toString

2007-11-06 Thread Graham Fawcett
On Nov 6, 2007 10:30 AM, Bayley, Alistair [EMAIL PROTECTED] wrote: From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Graham Fawcett Is there a way to declare a 'toString' function, such that toString x | x is a String = x toString x | x's type is an instance of Show = show x

Re: [Haskell-cafe] type/class question: toString

2007-11-06 Thread David Benbennick
On 11/6/07, Graham Fawcett [EMAIL PROTECTED] wrote: ToString.hs:5:0: Illegal instance declaration for `MyShow String' (The instance type must be of form (T a b c) where T is not a synonym, and a,b,c are distinct type variables) In the instance declaration for `MyShow

Re: [Haskell-cafe] type/class question: toString

2007-11-06 Thread Luke Palmer
I'm assuming you're not fond of the way the print function handles Strings? With GHC you can do this: {-# OPTIONS -fallow-overlapping-instances #-} {-# OPTIONS -fallow-undecidable-instances #-} class Show a = MyShow a where show_ :: a - String instance MyShow String where show_ s =

Re: [Haskell-cafe] type/class question: toString

2007-11-06 Thread Thomas Schilling
On Tue, 2007-11-06 at 09:18 -0500, Graham Fawcett wrote: Hi folks, Is there a way to declare a 'toString' function, such that toString x | x is a String = x toString x | x's type is an instance of Show = show x Perhaps, in the type system, there's a way to declare a ToString class, and

Re: [Haskell-cafe] type/class question: toString

2007-11-06 Thread Jeff Polakow
Hello, Have you tried using -fglasgow-exts? That should enable all ghc extensions. -Jeff [EMAIL PROTECTED] wrote on 11/06/2007 02:02:11 PM: On Nov 6, 2007 12:15 PM, David Benbennick [EMAIL PROTECTED] wrote: In ghc 6.8.1, the error messages are more helpful: foo.hs:5:0: Illegal

Re: [Haskell-cafe] type/class question: toString

2007-11-06 Thread Graham Fawcett
On Nov 6, 2007 12:03 PM, Thomas Schilling [EMAIL PROTECTED] wrote: On Tue, 2007-11-06 at 09:18 -0500, Graham Fawcett wrote: Hi folks, Is there a way to declare a 'toString' function, such that toString x | x is a String = x toString x | x's type is an instance of Show = show x I think

Re: [Haskell-cafe] type/class question: toString

2007-11-06 Thread Graham Fawcett
On Nov 6, 2007 2:21 PM, Jeff Polakow [EMAIL PROTECTED] wrote: Have you tried using -fglasgow-exts? That should enable all ghc extensions. Ah thanks, that does it. G ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] type/class question: toString

2007-11-06 Thread Graham Fawcett
On Nov 6, 2007 3:29 PM, Graham Fawcett [EMAIL PROTECTED] wrote: On Nov 6, 2007 2:21 PM, Jeff Polakow [EMAIL PROTECTED] wrote: Have you tried using -fglasgow-exts? That should enable all ghc extensions. If anyone's interested, I had best results when I added the flag

Re: [Haskell-cafe] type class question

2007-05-22 Thread Stefan Holdermans
Tim, If I have a type class for conversion to a type X: class XType a where toX :: a - X [...] instance XType String where toX = ... results in: Illegal instance declaration for `XType String' (The instance type must be of form (T a b c) where T is

Re: [Haskell-cafe] type class question

2007-05-22 Thread Henning Thielemann
On Tue, 22 May 2007, Tim Docker wrote: I think this must almost be a FAQ, or at least a PAQ (Previously AQ)... I think it too, thus I added your case to the Wiki: http://www.haskell.org/haskellwiki/List_instance ___ Haskell-Cafe mailing list

RE: [Haskell-cafe] type class question

2007-05-22 Thread Tim Docker
: Tuesday, 22 May 2007 10:11 PM To: Tim Docker Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] type class question On Tue, 22 May 2007, Tim Docker wrote: I think this must almost be a FAQ, or at least a PAQ (Previously AQ)... I think it too, thus I added your case to the Wiki: http

[Haskell-cafe] type class question

2007-05-21 Thread Tim Docker
I think this must almost be a FAQ, or at least a PAQ (Previously AQ)... If I have a type class for conversion to a type X: class XType a where toX :: a - X I can define instances for instance XType Int where toX = ... instance XType Double where toX = ...

Re: [Haskell-cafe] type class question

2007-05-21 Thread Derek Elkins
Tim Docker wrote: I think this must almost be a FAQ, or at least a PAQ (Previously AQ)... If I have a type class for conversion to a type X: class XType a where toX :: a - X I can define instances for instance XType Int where toX = ... instance XType Double

RE: [Haskell-cafe] type class question

2007-05-21 Thread Tim Docker
Derek Elkins wrote: I believe there is a trick where essentially you end up with, instance IsChar a = XType [a] where ... That is simple enough, and works fine. Thanks! Tim ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re[2]: [Haskell-cafe] class question

2007-01-24 Thread Bulat Ziganshin
Hello Hans, Sunday, January 21, 2007, 10:00:53 PM, you wrote: I understand this cannot be done in Haskell98, but it can with the GHC extension? Does {-# OPTIONS_GHC -fallow-undecidable-instances #-} refer to possibly infinite definitions? Thanks again! as usual i suggest you to read

[Haskell-cafe] class question

2007-01-21 Thread Hans van Thiel
Hello, I'm trying to understand classes and defined: class Monoid a where e :: a add :: a - a - a add a e = a add e a = a instance Monoid a Int where e = 0 add x y = x + y This works just fine, also for instance definitions of Char, Bool and lists. But defining: class (Num

Re: [Haskell-cafe] class question

2007-01-21 Thread Stefan O'Rear
On Sun, Jan 21, 2007 at 06:21:34PM +0100, Hans van Thiel wrote: class (Num a, Monoid a) = NumMon a where e = 0 add x y = x + y What am I doing wrong? Many thanks in advance. Nothing! What you are trying to do, declare a class B containing all members of a class A, is simply not

Re: [Haskell-cafe] class question

2007-01-21 Thread Hans van Thiel
On Sun, 2007-01-21 at 09:42 -0800, Stefan O'Rear wrote: On Sun, Jan 21, 2007 at 06:21:34PM +0100, Hans van Thiel wrote: class (Num a, Monoid a) = NumMon a where e = 0 add x y = x + y What am I doing wrong? Many thanks in advance. Nothing! What you are trying to do, declare a

Re: [Haskell-cafe] class question

2007-01-21 Thread Stefan O'Rear
On Sun, Jan 21, 2007 at 08:00:53PM +0100, Hans van Thiel wrote: On Sun, 2007-01-21 at 09:42 -0800, Stefan O'Rear wrote: This is the closest you'll get with GHC extensions: {-# OPTIONS_GHC -fallow-undecidable-instances #-} instance Num a = Monoid a where e = 0 add = (+)

Re: [Haskell-cafe] class question

2007-01-21 Thread Hans van Thiel
I. On Sun, 2007-01-21 at 11:20 -0800, Stefan O'Rear wrote: On Sun, Jan 21, 2007 at 08:00:53PM +0100, Hans van Thiel wrote: On Sun, 2007-01-21 at 09:42 -0800, Stefan O'Rear wrote: This is the closest you'll get with GHC extensions: {-# OPTIONS_GHC -fallow-undecidable-instances

RE: [Haskell] Type Class Question

2005-11-22 Thread Simon Peyton-Jones
: [Haskell] Type Class Question | | | Ah yes, but this forces me to write my instance of Show right away. I | cannot write: | | module A where data X = X | module B where | import A | bar x = show x -- here is the problem | moduel C where | import A | instance Show X where show x = X | module

[Haskell] Re: Type Class Question

2005-11-22 Thread oleg
Paul Govereau wrote: BTW, The above program is a translation of an idiomatic use of functors in ML (pardon my syntax): module A : sig type t = ... end module B : funsig(X:SHOW where t = A.t) sig bar : A.t - string end module C : SHOW where t = A.t open A open B(C) ML modules

[Haskell] Type Class Question

2005-11-21 Thread Paul Govereau
Hello, I was hoping that someone could answer a question I have about the type class system. In Haskell, I cannot write a term with an exact constraint: data X = X bar :: Show X = X - String bar x = show x According to the Haskell 98 report, a qualifier can only be applied to type variables,

Re: [Haskell] Type Class Question

2005-11-21 Thread Cale Gibbard
data X = X deriving Show bar :: X - String bar x = show x There's no need for the class constraint at all. If it's an instance of Show, then you're okay with just applying show to it. There's no need to actually assert that it's actually an instance of Show again. The only purpose of class

Re: [Haskell] Type Class Question

2005-11-21 Thread Paul Govereau
Ah yes, but this forces me to write my instance of Show right away. I cannot write: module A where data X = X module B where import A bar x = show x -- here is the problem moduel C where import A instance Show X where show x = X module Main where import A import B -- Show instance

Class Question

2003-01-22 Thread Matthew Donadio
Hi all, I have yet another question. I think I have too much time on my hands. I have two functions: rf :: (RealFloat a, Integral b) = [a] - b - Complex a rf x k = ... cf :: (RealFloat a, Integral b) = [Complex a] - b - Complex a cf x k = ... I would like to add these to the

Re: Class Question

2003-01-22 Thread Johan Baltié
Le Jeudi 23 Janvier 2003 06:40, Matthew Donadio a écrit : Hi all, I have yet another question. I think I have too much time on my hands. I have two functions: rf :: (RealFloat a, Integral b) = [a] - b - Complex a rf x k = ... cf :: (RealFloat a, Integral b) = [Complex a] - b