Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  I have question about Haskell (Baojun Wang)


----------------------------------------------------------------------

Message: 1
Date: Fri, 22 Apr 2016 05:44:28 +0000
From: Baojun Wang <wan...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] I have question about Haskell
Message-ID:
        <cac+a-tb6lsuo3xfrb22qj5bpn12vbhsqurifrgkxbvkavv4...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

putStr (show (polyEvaluate (coeffs) (read value :: Float) ))

Here ``polyEvaluate`` is inferred as a Show(able), However, ``polyEvaluate``
definition on the bottom returns a monad. (In haskell, meaning of return is
quite different than imperative programming language).

It's encouraged to write pure functions without effects, don't use monad
unless it's really necessary. rewrite ``polyEvaluate`` as below should make
the example compile.

polyEvaluate (coeffs) x = map (\(a, b) -> a+b) . zip coeffs . iterate (+1)
$ 0

Thanks
baojun

On Thu, Apr 21, 2016 at 8:33 PM Eunsu Kim <wntuw...@gmail.com> wrote:

> Hi
>
> i have a problem in my code!
>
> here is my code:
>
> -- Baic I/O and Loop (50 Points)
>
> evalpoly = do putStr "What is the degree of polynomial: "
> degree <- getLine
> coeffs <- (funcOfCoeff ((read degree::Int)+1) [])
> putStr "What value do you want to evaluate at: "
> value <- getLine
> putStr "The value of the polynomial is: "
> putStr (show (polyEvaluate (coeffs) (read value :: Float) ))
> putStr "\n"
>
> --function loop to get coefficient--
>
> funcOfCoeff 0 coeffs = do --to check the degree of 0
> return coeffs --return list of coefficient
>
> funcOfCoeff degree coeffs = do
> putStr ("What is the x^" ++ show(degree-1))
> putStr " coefficient: "
> coeff <- getLine
> loop <- funcOfCoeff (degree-1) ((read coeff :: Int) : coeffs)
> return loop
>
>
> polyEvaluate (coeffs) x = do
> powers <- zip coeffs (iterate (+1) 0)
> result <- map (\(a,b)-> a+b) powers ?PROBLEM IS HERE!!!!
> return result
>
> here is error message:
>
>
> in very bottom function (polyEvaluate), why is not working ?result <- map
> (\(a,b) -> a+b) powers? ???
>
> in Prelude, it is working
>
>
> Thanks!
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160422/6b5575eb/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2016-04-21 at 10.11.29 PM.png
Type: image/png
Size: 25586 bytes
Desc: not available
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160422/6b5575eb/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2016-04-21 at 10.12.30 PM.png
Type: image/png
Size: 12203 bytes
Desc: not available
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160422/6b5575eb/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2016-04-21 at 10.12.30 PM.png
Type: image/png
Size: 12203 bytes
Desc: not available
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160422/6b5575eb/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2016-04-21 at 10.11.29 PM.png
Type: image/png
Size: 25586 bytes
Desc: not available
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160422/6b5575eb/attachment-0003.png>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 94, Issue 20
*****************************************

Reply via email to