Ik heb hier een opdracht waar ik niet uit kom, ik zit er al een tijdje mee te prutsen en ik word er helemaal gek van.
Maar dit geeft de error:
Is hier iemand die inziet welke denkfout ik maak en hoe de functie wel moet (en waarom) ?
Nu had ik zelf het volgende bedacht:give the type of and define a function 'iter' so that
code:
1 iter n f x = f ( f ... ( f x ) ... ) )
where f occurs n times on the right-hand side of the equation. For instance we should have
code:
1 iter 3 f x = f ( f ( f x ) )
and iter 0 should return x.
code:
1
2
3
| iter :: Int -> (a -> a) -> a -> a
iter n f x | n == 0 = x
| otherwise = f (iter n-1 f x) |
Maar dit geeft de error:
code:
1
2
3
4
| ERROR "9.9.hs":2 - Inferred type is not general enough *** Expression : iter *** Expected type : Int -> (a -> a) -> a -> a *** Inferred type : Int -> (((a -> a) -> a -> a) -> (a -> a) -> a -> a) -> ((a -> a) -> a -> a) -> (a -> a) -> a -> a |
Is hier iemand die inziet welke denkfout ik maak en hoe de functie wel moet (en waarom) ?
[ Voor 12% gewijzigd door Aaargh! op 07-01-2006 19:24 ]
Those who do not understand Unix are condemned to reinvent it, poorly.