{- |
Description: Type class for de-lifting functions from embellished types.
License: GNU LGPLv3
Maintainer: paul.bittner@uni-ulm.de
Module for type class 'Defunctor' and some instances for Prelude types.
'Defunctor's can de-lift functions from embellished types to plain types.
-}
module Defunctor where
class Defunctor f where
demap :: (f a -> f b) -> a -> b
instance Defunctor Maybe where
demap :: (Maybe a -> Maybe b) -> a -> b
demap f :: Maybe a -> Maybe b
f x :: a
x = case Maybe a -> Maybe b
f (a -> Maybe a
forall a. a -> Maybe a
Just a
x) of
Just y :: b
y -> b
y
Nothing -> [Char] -> b
forall a. HasCallStack => [Char] -> a
error "Value cannot be defunctorialized!"
instance Defunctor [] where
demap :: ([a] -> [b]) -> a -> b
demap f :: [a] -> [b]
f x :: a
x = [b] -> b
forall a. [a] -> a
head ([b] -> b) -> [b] -> b
forall a b. (a -> b) -> a -> b
$ [a] -> [b]
f [a
x]