[Haskell-beginners] i have questions about Haskell
Simon Jakobi
simon.jakobi at googlemail.com
Sat Apr 23 03:58:30 UTC 2016
Hi!
> when outputting the polynomial value, actually write out the polynomial,
> but:
> - skipping any missing monomials
> - not including any extraneous signs
> -not showing the constant term
>
> for the above example, the final line would be:
>
> The value of 1.0 x^3 - 2.0 x^2 + 10.0 evaluated at -1.0 is 7.0
Because this is apparently a homework problem that you're supposed to
solve yourself, I'll only give you a few pointers:
What the problem description hints at is a function with type
Polynomial -> String.
So in a first step you should define that data type Polynomial (or
whatever you want to call it). So far you seem to have been using a
list of coefficients to represent polynomials, so you might just build
on that existing representation, either by creating a type alias or
creating a separate "real" type with a constructor.
In a second step you need to write a function Polynomial -> String
with an appropriate definition. I'd recommend that you start by
generating a simpler string representation like "1.0 x^3 + -2.0 x^2 +
0.0 x^1 + 10.0" and refine your definition iteratively.
Cheers,
Simon
More information about the Beginners
mailing list