In haskell's Poly package polynomials like x**2 + -1 are represented by [ -1, 0, 2] so for calculate the degree of a polynomial, I need to calculate the length of the polynomial list - 1.
This is what I have done:
polyDegree :: (Num a, Eq a) => Poly a -> Int
polyDegree p = rawPolyDegree (trim (0==) p)
rawPolyDegree :: Poly a -> Int
rawPolyDegree p = rawPolyLength p - 1
rawPolyLength :: Poly a -> Int
rawPolyLength (ListPoly _ _ cs) = length cs
rawPolyLength (VectorPoly _ _ cs) = V.length cs
rawPolyLength (UVectorPoly _ _ cs) = UV.length cs
I tried to compile this code. but doesn't work this code output this error
ghc -o main main.hs
[1 of 1] Compiling Main ( main.hs, main.o )
main.hs:1:32: error: Not in scope: type constructor or class `Poly'
|
1 | polyDegree :: (Num a, Eq a) => Poly a -> Int
| ^^^^
main.hs:4:18: error: Not in scope: type constructor or class `Poly'
|
4 | rawPolyDegree :: Poly a -> Int
| ^^^^
main.hs:7:18: error: Not in scope: type constructor or class `Poly'
|
7 | rawPolyLength :: Poly a -> Int
| ^^^^
main.hs:8:16: error: Not in scope: data constructor `ListPoly'
|
8 | rawPolyLength (ListPoly _ _ cs) = length cs
| ^^^^^^^^
main.hs:9:16: error: Not in scope: data constructor `VectorPoly'
|
9 | rawPolyLength (VectorPoly _ _ cs) = V.length cs
| ^^^^^^^^^^
main.hs:9:39: error:
Not in scope: `V.length'
No module named `V' is imported.
|
9 | rawPolyLength (VectorPoly _ _ cs) = V.length cs
| ^^^^^^^^
main.hs:10:16: error: Not in scope: data constructor `UVectorPoly'
|
10 | rawPolyLength (UVectorPoly _ _ cs) = UV.length cs
| ^^^^^^^^^^^
main.hs:10:38: error:
Not in scope: `UV.length'
No module named `UV' is imported.
|
10 | rawPolyLength (UVectorPoly _ _ cs) = UV.length cs
| ^^^^^^^^^
exit status 1
I researched here in stack overflow about problems compiling haskell function and I found a question about a simple algebra functions here I understand that my problem is that I have not instructed Haskell what the program should do the answer of this question is this:
main :: IO ()
main = print (f 2)
So accordingly to the question need to put this somewhere in my code but I don't know how where I have to put the values for this function?
I am studying with Programming in Haskell 2016 Graham Hutton 2nd Edition the book said is not important learn how to compile the snippets but I want to compile this snippets for check if my code is running. I am new in haskell, I am learning and interested in functional paradigm. I am using GHCi, version 8.6.5 Online Compiler for this.