[Haskell-beginners] making function problem (chapter 6 of Programming in Haskell)

Roelof Wobben rwobben at hotmail.com
Mon Aug 8 12:27:14 CEST 2011


Hello, 

After a short holiday I now studying chapter 6 of this book.

For the first exercise I have to make the function for ^ for postitive numbers.

So I did these steps.

Step 1 : Defining the type 

^ :: [Int] -> Int 

Step 2 : enumarate the cases 

^ []  = 
^ [n, 0] =
^ [n, ns] = 

Step 3 : Define the simple cases 

^ []  = []
^ [n.0] = 1 

Step 4 : Define the other cases 

^[n.ns] = n * ^ns

Step 5 : generalize and simplify :

^[] = []
^[-, 0] = 1 

So the whole function would be : 

^ :: [Int] -> Int 
^[]   = []
^[-, 0] = 1 
^ [n,ns] = n * ^ns 

But the answer in the book only says : 

m ^ 0 = 1 
m (n+1) = m * m ^n 

so no type defenition and a whole different solution to the last rule.

So my question is : Is what I did wrong ?

Roelof



 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110808/b311a2e1/attachment.htm>


More information about the Beginners mailing list