Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pierric/tuple-ops
various operations on n-ary tuples via GHC.Generics
https://github.com/pierric/tuple-ops
Last synced: 16 days ago
JSON representation
various operations on n-ary tuples via GHC.Generics
- Host: GitHub
- URL: https://github.com/pierric/tuple-ops
- Owner: pierric
- License: bsd-3-clause
- Created: 2018-01-16T11:46:13.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-08-15T19:02:58.000Z (over 4 years ago)
- Last Synced: 2024-04-23T07:18:43.451Z (9 months ago)
- Language: Haskell
- Size: 25.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tuple-ops
operations on n-ary tuples by manipulating via GHC.Generics. Current only uncons is implemented.## uncons
```
> uncons (1::Int)
(1,())
``````
> uncons (1::Int,'a')
(1,'a')
``````
> uncons (True,'a', "S")
(True,('a',"S"))
```## design rational
uncons initially targets to work with C interfaces generated from C2HS. For example, the following definition```
{#fun MXSymbolInferShape as mxSymbolInferShapeImpl
{ id `SymbolHandle'
, id `MXUInt'
, withStringArray* `[String]'
, withIntegralArray* `[Int]'
, withIntegralArray* `[Int]'
, alloca- `MXUInt' peek*
, alloca- `Ptr MXUInt' peek*
, alloca- `Ptr (Ptr MXUInt)' peek*
, alloca- `MXUInt' peek*
, alloca- `Ptr MXUInt' peek*
, alloca- `Ptr (Ptr MXUInt)' peek*
, alloca- `MXUInt' peek*
, alloca- `Ptr MXUInt' peek*
, alloca- `Ptr (Ptr MXUInt)' peek*
, alloca- `Int' peekIntegral*
} -> `Int' #}
```generates a function that returns `(Int, MXUInt, Ptr MXUInt, Ptr (Ptr MXUInt), MXUInt, Ptr MXUInt, Ptr (Ptr MXUInt),
MXUInt, Ptr MXUInt, Ptr (Ptr MXUInt), Int)`, in which the first element is return code. By `uncons` it, we can extract the
return code, throwing an exception when an error is indicated, and return the rest part as result.`uncons` also fits a function returning a return-code only. In this case, `()` is the result after extraction.
## limits
only tuple of size up to 16 is supported.