Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nwtgck/open-union-sugar-haskell
Syntactic sugar for open-union
https://github.com/nwtgck/open-union-sugar-haskell
haskell haskell-library open-union quasiquoter template-haskell
Last synced: 9 days ago
JSON representation
Syntactic sugar for open-union
- Host: GitHub
- URL: https://github.com/nwtgck/open-union-sugar-haskell
- Owner: nwtgck
- License: bsd-3-clause
- Created: 2018-02-18T08:10:49.000Z (almost 7 years ago)
- Default Branch: develop
- Last Pushed: 2018-04-21T02:37:46.000Z (over 6 years ago)
- Last Synced: 2024-10-26T17:24:08.388Z (about 2 months ago)
- Topics: haskell, haskell-library, open-union, quasiquoter, template-haskell
- Language: Haskell
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# open-union-sugar
| branch | status|
| --- | --- |
| [`master`](https://github.com/nwtgck/open-union-sugar-haskell/tree/master) | [![Build Status](https://travis-ci.org/nwtgck/open-union-sugar-haskell.svg?branch=master)](https://travis-ci.org/nwtgck/open-union-sugar-haskell) |
| [`develop`](https://github.com/nwtgck/open-union-sugar-haskell/tree/develop) | [![Build Status](https://travis-ci.org/nwtgck/open-union-sugar-haskell.svg?branch=develop)](https://travis-ci.org/nwtgck/open-union-sugar-haskell) |Syntactic sugar for [open-union](https://hackage.haskell.org/package/open-union)
## Install
### For [Stack](https://docs.haskellstack.org/en/stable/README/) users
Add this library to `extra-deps` in your `stack.yaml` like the following.
```yaml
...
extra-deps:
- git: https://github.com/nwtgck/open-union-sugar-haskell.git
commit: 24ad5c35054dc511308bb5186cf17784042c499a
...
```Then, add `open-union-sugar` to your `package.yaml` like the following.
```yaml
...
library:
dependencies:
- open-union-sugar
...
```## Usage
### `l` quote
```hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE QuasiQuotes #-}import Data.OpenUnion
import Data.OpenUnion.Sugarmain :: IO ()
main = do
let u1 :: Union '[Int, String]
u1 = [l|"hello"|]
print u1
-- => Union ("hello" :: [Char])
```### `hlist` quote
```hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE QuasiQuotes #-}import Data.OpenUnion
import Data.OpenUnion.Sugarmain :: IO ()
main = do
let hlist1 :: [Union '[Char, Bool, String]]
hlist1 = [hlist|
'a'
, True
, "apple"
, 'z'
, False
, "orange"
|]
print hlist1
-- => [Union ('a' :: Char),Union (True :: Bool),Union ("apple" :: [Char]),Union ('z' :: Char),Union (False :: Bool),Union ("orange" :: [Char])]
```### `ptn` quote
```hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}import Data.OpenUnion
import Data.OpenUnion.Sugartype UnitList = [()]
showMyUnion :: Union '[Char, Int, String, UnitList] -> String
[ptn|
showMyUnion (c :: Char) = "char: " ++ show c
showMyUnion (i :: Int) = "int: " ++ show i
showMyUnion (s :: String) = "string: " ++ s
showMyUnion (l :: UnitList) = "list length: " ++ show (length l)
|]main :: IO ()
main = do
let u1 :: Union '[Char, Int, String, UnitList]
u1 = [l|"hello"|]
putStrLn (showMyUnion u1)
-- => string: hellolet u2 :: Union '[Char, Int, String, UnitList]
u2 = [l|189 :: Int|]
putStrLn (showMyUnion u2)
-- => int: 189
```