| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
NAryFunctor
Contents
Documentation
class NFunctor (f :: k) where Source #
A generalization of Functor, Bifunctor, Trifunctor, etc.
Example usage:
>>>nmap <#> (+1) $ Identity (0::Int)Identity 1
>>>nmap <#> (+1) <#> (+2) $ (0::Int, 0::Int)(1,2)
>>>nmap <#> (+1) <#> (+2) <#> (+3) $ (0::Int, 0::Int, 0::Int)(1,2,3)
Laws:
nmap <#> id <#> ... <#> id = id (nmap <#> f1 <#> ... <#> fN) . (nmap <#> g1 <#> ... <#> gN) = nmap <#> (f1 . g1) <#> ... <#> (fN . gN)
Example instance:
instance NFunctor (,,) where
nmap = NMap1 $ \f1
-> NMap1 $ \f2
-> NMap1 $ \f3
-> \(x1,x2,x3)
-> (f1 x1, f2 x2, f3 x3)Minimal complete definition
Instances
| NFunctor * () Source # | For kind
|
| NFunctor (* -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *) (,,,,,,,,,,,,,,) Source # | |
| NFunctor (* -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *) (,,,,,,,,,,,,,) Source # | |
| NFunctor (* -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *) (,,,,,,,,,,,,) Source # | |
| NFunctor (* -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *) (,,,,,,,,,,,) Source # | |
| NFunctor (* -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *) (,,,,,,,,,,) Source # | |
| NFunctor (* -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *) (,,,,,,,,,) Source # | |
| NFunctor (* -> * -> * -> * -> * -> * -> * -> * -> * -> *) (,,,,,,,,) Source # | |
| NFunctor (* -> * -> * -> * -> * -> * -> * -> * -> *) (,,,,,,,) Source # | |
| NFunctor (* -> * -> * -> * -> * -> * -> * -> *) (,,,,,,) Source # | |
| NFunctor (* -> * -> * -> * -> * -> * -> *) (,,,,,) Source # | |
| NFunctor (* -> * -> * -> * -> * -> *) (,,,,) Source # | |
| NFunctor (* -> * -> * -> * -> *) (,,,) Source # | |
| NFunctor (* -> * -> * -> *) (,,) Source # | |
| NFunctor (* -> * -> *) Either Source # | For kind
|
| NFunctor (* -> * -> *) (,) Source # | |
| NFunctor (* -> *) Identity Source # | |
| NFunctor (* -> *) (Either a) Source # | For kind
|
Internals
newtype NMap1 k (f :: Type -> k) (f' :: Type -> k) Source #
Types like Either which have both a Functor and a Bifunctor instance
can have more than one NFunctor instance. Those instances all define the
same method, nmap, but they return a value of a different type, which is
how the correct NFunctor instance is picked:
nmap :: NMap1 Type (Either a) (Either a) -- Functor nmap :: NMap1 (Type -> Type) Either Either -- Bifunctor
This NMap1 is unwrapped by using <#> to pass in the next input function.
In the case of NMap1 (Type -> Type), the result after passing this input
function is another NMap1, which needs to be unwrapped using a second
<#>. The end result is that the Functor behaviour is obtained by using a
single <#>, and the Bifunctor behaviour is obtained by using two.
>>>nmap <#> (+1) $ Right (0::Int)Right 1>>>nmap <#> (+1) <#> (+2) $ Left (0::Int)Left 1