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
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
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
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
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,
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
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
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
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
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.
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-
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:
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.
___
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
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] -
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
16 matches
Mail list logo