Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/athanclark/poly-arity
Tools for working with functions without regard to their arity
https://github.com/athanclark/poly-arity
arity haskell poly-arity
Last synced: 6 days ago
JSON representation
Tools for working with functions without regard to their arity
- Host: GitHub
- URL: https://github.com/athanclark/poly-arity
- Owner: athanclark
- License: bsd-3-clause
- Created: 2015-04-25T17:38:18.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-19T04:24:04.000Z (almost 8 years ago)
- Last Synced: 2023-04-10T16:35:21.359Z (over 1 year ago)
- Topics: arity, haskell, poly-arity
- Language: Haskell
- Size: 12.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
poly-arity
==========> Tools for working with functions of undetermined arity.
Most of these tools are type-level constructs to ensure that your function types
will have a certain initial shape, because the function arrow `->` itself makes
a type-level list, where each `(->)` would be like `(:)`.## Usage
Your first try might look something like this:
```haskell
{-# LANGUAGE
TypeFamilies
, TypeOperators
, DataKinds
, PolyKinds
, ConstraintKinds
, KindSignatures
, AllowAmbiguousTypes
#-}module Example where
import Data.Function.Poly
import Data.HListtype family (xs :: [k]) :++ (ys :: [k]) :: [k] where
'[] :++ ys = ys
(x ': xs) :++ ys = x ': xs :++ ysfoo :: ( TypeListToArity xs r ~ f -- Proves the arity - list isomorphism
, ArityToTypeList f ~ (:++) xs (r ': '[])
) => f -> f
foo = idbar :: ( ArityMinusTypeList f xs ~ r -- Proves replacement
, ExpectArity xs f
) => f -> f
bar = id-- warning - the above don't actually work :\
xs :: HList (Integer ': Bool ': Maybe () ': '[])
xs = HCons (5 :: Integer) $ HCons True $ HCons (Just ()) HNilbaz :: Integer -> Bool -> Maybe () -> String -> ()
baz _ _ _ _ = ()
```then, we can toy with `appN` in `ghci`:
```haskell
λ> :t baz `appN` xs
baz `appN` xs :: String -> ()
```