HI && TypeCast

Derek Elkins ddarius@hotpop.com
Wed, 6 Aug 2003 17:49:28 -0400


On Wed, 6 Aug 2003 23:24:13 +0200
"Fredrik Petersson" <fredde@x-web.se> wrote:

> Hi there!
> Iam new to the list so feel free to shout at me when i do wrong! :)
> Software-designer from sweden, likes fast bikes and metal, thats me,
> and hi to you all!
> 
> Yeah ok to the problem,
> i have this stupid code,
> [c | (c,i) <- l]
> 
> Where (c,i) are a tuple from a (Char,Int) and l is a [(Char,Int)]
> So far everthings nice but i would like to cast the c to a Sting and
> add : in front,
> So if i fry with a list like [('d',3)('f',3)]
> I end up with
> "fg" but i want it to look like
> ":f :g"

":d :f", ay? ;)

> 
> piece of cake, huh?
> Give me a hit or a webpage to read more from...?

www.haskell.org/learning

> How do you TypeCast in haskell?

You don't.  Anyway's what you want isn't a "typecast" in any language.

concat [[':',c] | (c,i) <- l] 
-- actually this will give you ":f:g"
-- concat (intersperse " " [[':',c] | (c,i) <- l]) will give you ":f :g"
-- I think intersperse is in module List (Data.List) by the way.