Re: [Haskell-cafe] How to define Show [MyType] ?

2008-12-09 Thread Wouter Swierstra
The biggest wart is that view is not a total function; the compiler needs to be extra careful to only call it on types that are instances of View. I wonder if there is a good way to solve this problem? The usual way to solve this is to define a data type corresponding to all the types in

Re: [Haskell-cafe] How to define Show [MyType] ?

2008-12-09 Thread Ryan Ingram
Interesting. But from a practical point of view (I know, irrelevant! *grin*), it's very tempting to piggyback the entirety of the typeclass feature on a simple technique like this. It also gives you the benefit that functions like this: manyConstraints :: (Show a, Eq a, Data a) = a - Bool end

Re: [Haskell-cafe] How to define Show [MyType] ?

2008-12-08 Thread Ryan Ingram
On Sun, Dec 7, 2008 at 1:51 AM, Fraser Wilson [EMAIL PROTECTED] wrote: (I know you know this, I just have this weird fascination with the showList wart, although for the life of me I can't think of a better way of doing it) Well, if you extend the compiler's core language with typecase, you can

Re: [Haskell-cafe] How to define Show [MyType] ?

2008-12-07 Thread Ryan Ingram
On Sat, Dec 6, 2008 at 3:39 PM, Dmitri O.Kondratiev [EMAIL PROTECTED] wrote: Daniel, thanks! I used your advice, it works, yet some more questions, if you don't mind :) So: {-- Why showList returns a function of type: type ShowS = String - String In fact showList returns a function which

Re: [Haskell-cafe] How to define Show [MyType] ?

2008-12-07 Thread Fraser Wilson
1) They come from the show instance for String. Try putStrLn (t2 fleet) instead. pedant The show instance for Char. /pedant (I know you know this, I just have this weird fascination with the showList wart, although for the life of me I can't think of a better way of doing it) cheers,

Re: [Haskell-cafe] How to define Show [MyType] ?

2008-12-06 Thread Dmitri O.Kondratiev
Daniel, thanks! I used your advice, it works, yet some more questions, if you don't mind :) So: {-- Why showList returns a function of type: type ShowS = String - String In fact showList returns a function which already contains all values from list converted to a single string. Why return

Re: [Haskell-cafe] How to define Show [MyType] ?

2008-12-05 Thread Jules Bean
Dmitri O.Kondratiev wrote: I am trying to define instance Show[MyType] so show (x:xs :: MyType) would return a single string where substrings corresponding to list elements will be separated by \n. This would allow pretty printing of MyType list in several lines instead of one, as default Show

Re: [Haskell-cafe] How to define Show [MyType] ?

2008-12-05 Thread Henning Thielemann
Jules Bean schrieb: Dmitri O.Kondratiev wrote: I am trying to define instance Show[MyType] so show (x:xs :: MyType) would return a single string where substrings corresponding to list elements will be separated by \n. This would allow pretty printing of MyType list in several lines instead

Re: [Haskell-cafe] How to define Show [MyType] ?

2008-12-05 Thread Dmitri O.Kondratiev
On Fri, Dec 5, 2008 at 1:29 AM, Martijn van Steenbergen [EMAIL PROTECTED] wrote: Dmitri O.Kondratiev wrote: -- How to define Show [MyType] ? Define instance Show MyType and implement not only show (for 1 value of MyType) but also showList, which Show provides as well. You can do all the

Re: [Haskell-cafe] How to define Show [MyType] ?

2008-12-05 Thread Martijn van Steenbergen
Dmitri O.Kondratiev wrote: Thanks everybody for your help! I tried to implement showList, but get the same error: That's because you're trying to implement instance Show [MyType], but you have to implement instance Show MyType instead, without the []. Groetjes, Martijn.

Re: [Haskell-cafe] How to define Show [MyType] ?

2008-12-05 Thread Daniel Fischer
Am Samstag, 6. Dezember 2008 00:13 schrieb Dmitri O.Kondratiev: Thanks everybody for your help! I tried to implement showList, but get the same error: {-- -- from Prelude: type *ShowS* = Stringfile:///C:/usr/ghc-6.6.1/doc/html/libraries/base/Prelude.html#t%3ASt ring-

[Haskell-cafe] How to define Show [MyType] ?

2008-12-04 Thread Dmitri O.Kondratiev
I am trying to define instance Show[MyType] so show (x:xs :: MyType) would return a single string where substrings corresponding to list elements will be separated by \n. This would allow pretty printing of MyType list in several lines instead of one, as default Show does for lists. For example:

Re: [Haskell-cafe] How to define Show [MyType] ?

2008-12-04 Thread Martijn van Steenbergen
Dmitri O.Kondratiev wrote: -- How to define Show [MyType] ? Define instance Show MyType and implement not only show (for 1 value of MyType) but also showList, which Show provides as well. You can do all the magic in there. HTH, Martijn. ___

Re: [Haskell-cafe] How to define Show [MyType] ?

2008-12-04 Thread Jonathan Cast
On Fri, 2008-12-05 at 01:27 +0300, Dmitri O.Kondratiev wrote: I am trying to define instance Show[MyType] so show (x:xs :: MyType) would return a single string where substrings corresponding to list elements will be separated by \n. This would allow pretty printing of MyType list in several

Re: [Haskell-cafe] How to define Show [MyType] ?

2008-12-04 Thread Ryan Ingram
If you really, really wanted to define Show [ShipInfo], then putting {-# LANGUAGE FlexibleInstances, OverlappingInstances #-} at the beginning of your file would work. At the cost of using overlapping instances, of course. And at the cost of causing code like this: f :: Show a = [a] -

Re: [Haskell-cafe] How to define Show [MyType] ?

2008-12-04 Thread Jonathan Cast
On Thu, 2008-12-04 at 14:46 -0800, Ryan Ingram wrote: If you really, really wanted to define Show [ShipInfo], then putting {-# LANGUAGE FlexibleInstances, OverlappingInstances #-} at the beginning of your file would work. At the cost of using overlapping instances, of course. And