Reputation: 1229
I have 2 type definitions
type Mapper a k v = a -> [(k,v)]
type MapperM m a k v = a -> m [(k,v)]
I want to write a function that convert a value from type
(Ord k, Monad m) => MapperM m a k v
to type
Ord k => Mapper a k v
basically a function that takes a -> m [(k,v)] as an argument and return a -> [(k,v)] as output.
All my attempts are failing with the Haskell type checks.
Upvotes: 1
Views: 147
Reputation: 332
I believe it is mathematically impossible.
Consider the case when m is Maybe: the function could return [(k,v)] from Just [(k,v)], but what would it return from Nothing?
If the monad is IO, extracting the argument from the monad would break the safety that IO provides.
Also consider that your function would have to work for any conceivable monad.
Upvotes: 3