Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: question on evaluation (Fabien R)
2. Re: question on evaluation (Rein Henrichs)
3. Re: question on evaluation (Fabien R)
----------------------------------------------------------------------
Message: 1
Date: Sun, 10 Jan 2016 22:32:47 +0100
From: Fabien R <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] question on evaluation
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed
On 10/01/16 00:54, Theodore Lief Gannon wrote:
> And the reason calling myReverse on that doesn't give you [1, 2, 3, 4] is
> that you're reversing a different list every time:
Got it.
>
> (...)
>
> Since you only asked for help with how it evaluates, I'll withhold further
> spoilers. :) However, I strongly recommend getting more comfortable using
> the (:) operator for construction instead of just pattern matching; in a
> couple of your functions it would be a better tool than (++).
I'll dig further into that.
Also,
> "at-patterns" are great:
>
> blowup l@(x:xs) = myRepeat x (head (buildLenList l)) ++ blowup xs
This is handy.
Thanks Theodore,
--
Fabien
> On Sat, Jan 9, 2016 at 7:21 AM, Fabien R <[email protected]> wrote:
>
>> Hello,
>>
>> I want to define a function blowup that takes "bang" as input and returns
>> "baannngggg".
>> I come up with these functions;
>>
>> myReverse :: [a] -> [a]
>> myReverse [] = []
>> myReverse (x:xs) = myReverse xs ++ [x]
>>
>> buildLenList :: String -> [Int]
>> buildLenList "" = []
>> buildLenList (_:xs) = [1 + length xs ] ++ buildLenList xs
>>
>> myRepeat :: Char -> Int -> String
>> myRepeat x 0 = []
>> myRepeat x n = [x] ++ myRepeat x (n - 1)
>>
>> blowup :: String -> String
>> blowup [] = []
>> blowup (x:xs) = myRepeat x (head ( (buildLenList (x:xs)))) ++ blowup xs
>>
>> With this code, blowup "bang" returns "bbbbaaanng".
>>
>> So I thought to insert myReverse between head and buildLenList but in that
>> case, the result is only "bang".
>>
>> It seems that the evaluation of buildLenList is not working as I thought.
>> I tried to debug that using ghci debugger but failed (still learning).
>> Can someone explain how the evaluation is done here ?
>>
>> --
>> Fabien
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
------------------------------
Message: 2
Date: Mon, 11 Jan 2016 05:24:31 +0000
From: Rein Henrichs <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] question on evaluation
Message-ID:
<CAJp6G8ytBADrs6RTMgY_cd+wK9DCO_JTi2mxOSUy7zUX=J=w...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Now that you understand what's going on with your version, here's an
idiomatic definition of blowup for you to consider:
blowup :: String -> String
blowup = join . zipWith replicate [1..]
> blowup "bang"
"baannngggg"
On Sun, Jan 10, 2016 at 1:33 PM Fabien R <[email protected]> wrote:
> On 10/01/16 00:54, Theodore Lief Gannon wrote:
> > And the reason calling myReverse on that doesn't give you [1, 2, 3, 4] is
> > that you're reversing a different list every time:
> Got it.
> >
> > (...)
> >
> > Since you only asked for help with how it evaluates, I'll withhold
> further
> > spoilers. :) However, I strongly recommend getting more comfortable
> using
> > the (:) operator for construction instead of just pattern matching; in a
> > couple of your functions it would be a better tool than (++).
> I'll dig further into that.
>
> Also,
> > "at-patterns" are great:
> >
> > blowup l@(x:xs) = myRepeat x (head (buildLenList l)) ++ blowup xs
> This is handy.
>
> Thanks Theodore,
>
> --
> Fabien
>
> > On Sat, Jan 9, 2016 at 7:21 AM, Fabien R <[email protected]> wrote:
> >
> >> Hello,
> >>
> >> I want to define a function blowup that takes "bang" as input and
> returns
> >> "baannngggg".
> >> I come up with these functions;
> >>
> >> myReverse :: [a] -> [a]
> >> myReverse [] = []
> >> myReverse (x:xs) = myReverse xs ++ [x]
> >>
> >> buildLenList :: String -> [Int]
> >> buildLenList "" = []
> >> buildLenList (_:xs) = [1 + length xs ] ++ buildLenList xs
> >>
> >> myRepeat :: Char -> Int -> String
> >> myRepeat x 0 = []
> >> myRepeat x n = [x] ++ myRepeat x (n - 1)
> >>
> >> blowup :: String -> String
> >> blowup [] = []
> >> blowup (x:xs) = myRepeat x (head ( (buildLenList (x:xs)))) ++ blowup
> xs
> >>
> >> With this code, blowup "bang" returns "bbbbaaanng".
> >>
> >> So I thought to insert myReverse between head and buildLenList but in
> that
> >> case, the result is only "bang".
> >>
> >> It seems that the evaluation of buildLenList is not working as I
> thought.
> >> I tried to debug that using ghci debugger but failed (still learning).
> >> Can someone explain how the evaluation is done here ?
> >>
> >> --
> >> Fabien
> >> _______________________________________________
> >> Beginners mailing list
> >> [email protected]
> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >>
> >
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20160111/d4f05438/attachment-0001.html>
------------------------------
Message: 3
Date: Mon, 11 Jan 2016 09:41:07 +0100
From: Fabien R <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] question on evaluation
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252
On 11/01/2016 06:24, Rein Henrichs wrote:
> Now that you understand what's going on with your version, here's an
> idiomatic definition of blowup for you to consider:
>
> blowup :: String -> String
> blowup = join . zipWith replicate [1..]
>
> > blowup "bang"
> "baannngggg"
Thanks for this "hint" Rein.
But, for now, it's a kind of "forward reference". I will certainly come
up with a similar solution later.
--
Fabien
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 91, Issue 17
*****************************************