I'm new to haskell, and i'm trying to use operand .
function strangeMaths has to be smth like logBase 2 ((max x)^3) but using 3 functions and operand . so i did this code
strangeMaths = f . g . h
f = logBase 2
g = (^3)
h = max
but this gives me an error:
No instance for (Ord a0) arising from a use of `max'
The type variable `a0' is ambiguous
Relevant bindings include
h :: a0 -> a0 -> a0 (bound at 14)doItYourSelf.hs:7:1)
Note: there are several potential instances:
instance Integral a => Ord (GHC.Real.Ratio a)
-- Defined in `GHC.Real'
instance Ord () -- Defined in `GHC.Classes'
instance (Ord a, Ord b) => Ord (a, b) -- Defined in `GHC.Classes'
...plus 23 others
In the expression: max
In an equation for `h': h = max
Failed, modules loaded: none.
P.S. i know that log (a, b^c) = c*log (a, b) but this is an example.
Your problem is that
maxtakes two arguments, not one.Let's inspect the signature of
.:We clearly see that these take functions that take one argument and 'chain' them together.
Now let's have a look at
max:This is a function that takes two arguments, or in other words takes one argument, then returns another function. So, for instance,
max 1 :: Int -> Int.Now let's take a look at
g . h, a part of the function you're trying to write:Then we have a problem:
max ais a function, not a floating point value. Hence the compiler complains. This is equivalent to trying to computemap^2orreverse^2; it's completely nonsensical.Unfortunately you have not stated what
strangeMathsshould actually do, so I can't tell you how you should write it. However, there are a few ways to solve the issue:hasmax 1(instead ofmax), or some other similar value.strangeMathsas(.) (f . g) . h.Floatinginstance for functions of the forma -> a. (I don't know how or why you would do this, but it's possible.)I suspect that the second case is true, as this would mean that
strangeMaths x y = logBase 2 ((max x y)^2), which makes a lot more sense.