Now, obviously, the problem is that fst and snd, being passed in a list, needs to be of the same type; this complicates classifying a list of type [(Int,Bool)], for instance¹.
I have a similar problem. Say I have a record:
data Rec = Rec { a :: Int, b :: Type1, c :: Type2, d :: Type3, ... } rec = Rec { a = 1, b = ... }
Now I want to print part of the record. What I would like to do is the following
putStrLn $ concatMap show [a,c,d]
!!! bang !!! So what I actually do is
putStrLn $ concat [show a, show c, show d]
Works, but a little bit clumsy, especially with long lists. Is there a nice solution? Markus
On Wed, Jun 04, 2003 at 02:46:59PM +0200, Markus.Schnell@infineon.com wrote:
So what I actually do is
putStrLn $ concat [show a, show c, show d]
Works, but a little bit clumsy, especially with long lists. Is there a nice solution?
One way is to define a special (polymorphic) combinator instead of forcing everything into a list: infixr |+ a |+ b = shows a b and then just: putStrLn $ a |+ c |+ d |+ "" This is hopefully reasonably concise. Lauri Alanko la@iki.fi
On Wed, Jun 04, 2003 at 02:46:59PM +0200, Markus.Schnell@infineon.com wrote:
Now I want to print part of the record. What I would like to do is the following
putStrLn $ concatMap show [a,c,d]
!!! bang !!!
So what I actually do is
putStrLn $ concat [show a, show c, show d]
Works, but a little bit clumsy, especially with long lists. Is there a nice solution?
You can do something like this: infixr 5 +++ (+++) :: Show a => a -> [String] -> [String] a +++ l = show a : l concat $ a +++ b +++ c +++ [] Best regards, Tom -- .signature: Too many levels of symbolic links
participants (3)
-
Lauri Alanko -
Markus.Schnell@infineon.com -
Tomasz Zielonka