Problem
I am just going through the You Could Have Invented Monads! tutorial, and in the section entitled A Container: Multivalued Functions, where the function types (of complex square and cube roots) are:
Complex Float -> [Complex Float]
Bind is defined as:
bind :: (Complex Double -> [Complex Double]) -> ([Complex Double] -> [Complex Double])
bind f x = concat (map f x)
--shortcut:
f * g = bind f . g
and unit and lift are:
unit x = [x]
lift f = unit . f
Now I am confused, is the f in lift function the same as the f in the bind function?
In other words what are the type of the unit and lift functions?
Paradox
Also, by my reasoning I come to a strange paradox: If lift can take functions such as:
realRoot :: Double -> Double
realRoot x = sqrt(x)
and lift it into our monad so that it becomes of type:
lift realRoot :: [Complex Double]
wouldn’t I be able to do stuff like:
(lift realRoot * imaginaryRoot) -1
where
imaginaryRoot :: [Complex Double]
But how can I take real root of complex numbers?
Any help appreciated!
No, it’s not the same.
lift‘s argument is a functionComplex Double -> Complex Double, soand thus your
realRootis not an acceptable argument forlift.