[Haskell-beginners] I have question about Haskell
Chul-Woong Yang
cwyang at aranetworks.com
Fri Apr 22 05:57:55 UTC 2016
Do you intend to use list monad?
Since you bind the result of zip into powers,
powers has type (a,b).
try changing that line:
> let powers = zip coeffs (iterate (+1) 0)
As Baojun says, you'd better to write pure function
and isolate I/O from it.
2016-04-22 12:33 GMT+09:00 Eunsu Kim <wntuwntu at gmail.com>:
> 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 at 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/1944c97b/attachment-0001.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/1944c97b/attachment-0002.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/1944c97b/attachment-0003.png>
More information about the Beginners
mailing list