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 =
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
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?
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
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
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
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 =
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
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
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
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
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
12 matches
Mail list logo