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] 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

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] 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