Hello all,
I am trying to figure out why does compiler need manual lifting from String
to Monad String
if it can detect that both work with String
. We know that wraping String
in pure
is safe and it will result in Monad String
. Why am I forced to do manual pure lifting instead of compiler doing it automatically ?
Examples:
Lets say I have: (pseudo code)
transform :: String -> String
transform a = a
mtransform2 :: Maybe String -> String
mtransform2 (Just a) = a
mtransform2 Nothing = ""
transform >>> mtransform2 -- this will not work because String is not M String
-- there is no reason why concrete String type cannot be automatically
-- changed to M String
-- I am forced to do
transform >>> pure >>> mtransform2
This logic can be applied to other monads too
why I cannot plug any String
to any function which has m String
examples:
func :: String -> String
func a = a
func1 :: Array String -> String
func1 x:xs = x
func1 [] = ''
func2 :: Effect String -> String
func2 (Effect a) = a -- ?? dunno how to get value from this
func2 _ = ''
func3 :: Either String -> String
func3 (Right a) = a
func3 (Left _) = ''
-- so I want this
func "string"
func1 "string" -- this should work
func1 ["string"] -- as well as this should work
func2 "string"
func3 "string"
-- compiler knows context and
-- can use pure when it needs to automatically
etc. You get the point.
Now, why am I forced to create func
if I only want to create any of other Monad version of the function ?
So my question is. Why does compiler create such strict rules when it can perform lifting by itself.