<div dir="ltr">Now that you understand what's going on with your version, here's an idiomatic definition of blowup for you to consider:<div><br></div><div>    blowup :: String -> String</div><div>    blowup = join . zipWith replicate [1..]</div><div><br></div><div>    > blowup "bang"</div><div>    "baannngggg"</div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Jan 10, 2016 at 1:33 PM Fabien R <<a href="mailto:theedge456@free.fr">theedge456@free.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 10/01/16 00:54, Theodore Lief Gannon wrote:<br>
> And the reason calling myReverse on that doesn't give you [1, 2, 3, 4] is<br>
> that you're reversing a different list every time:<br>
Got it.<br>
><br>
> (...)<br>
><br>
> Since you only asked for help with how it evaluates, I'll withhold further<br>
> spoilers. :)  However, I strongly recommend getting more comfortable using<br>
> the (:) operator for construction instead of just pattern matching; in a<br>
> couple of your functions it would be a better tool than (++).<br>
I'll dig further into that.<br>
<br>
Also,<br>
> "at-patterns" are great:<br>
><br>
> blowup l@(x:xs) =  myRepeat x (head (buildLenList l)) ++ blowup xs<br>
This is handy.<br>
<br>
Thanks Theodore,<br>
<br>
--<br>
Fabien<br>
<br>
> On Sat, Jan 9, 2016 at 7:21 AM, Fabien R <<a href="mailto:theedge456@free.fr" target="_blank">theedge456@free.fr</a>> wrote:<br>
><br>
>> Hello,<br>
>><br>
>> I want to define a function blowup that takes "bang" as input and returns<br>
>> "baannngggg".<br>
>> I come up with these functions;<br>
>><br>
>> myReverse :: [a] -> [a]<br>
>> myReverse [] = []<br>
>> myReverse (x:xs) = myReverse xs ++ [x]<br>
>><br>
>> buildLenList :: String -> [Int]<br>
>> buildLenList "" = []<br>
>> buildLenList (_:xs) = [1 + length xs ] ++ buildLenList xs<br>
>><br>
>> myRepeat :: Char -> Int -> String<br>
>> myRepeat x 0 = []<br>
>> myRepeat x n = [x] ++ myRepeat x (n - 1)<br>
>><br>
>> blowup :: String -> String<br>
>> blowup [] = []<br>
>> blowup (x:xs) =  myRepeat x (head ( (buildLenList (x:xs)))) ++ blowup  xs<br>
>><br>
>> With this code, blowup "bang" returns "bbbbaaanng".<br>
>><br>
>> So I thought to insert myReverse between head and buildLenList but in that<br>
>> case, the result is only "bang".<br>
>><br>
>> It seems that the evaluation of buildLenList is not working as I thought.<br>
>> I tried to debug that using ghci debugger but failed (still learning).<br>
>> Can someone explain how the evaluation is done here ?<br>
>><br>
>> --<br>
>> Fabien<br>
>> _______________________________________________<br>
>> Beginners mailing list<br>
>> <a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
>> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
>><br>
><br>
><br>
><br>
> _______________________________________________<br>
> Beginners mailing list<br>
> <a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
><br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>