hset (empty) → 0.0.1
raw patch · 5 files changed
+120/−0 lines, 5 filesdep +basesetup-changed
Dependencies added: base
Files
- CHANGELOG.md +4/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- hset.cabal +30/−0
- src/Data/HSet.hs +54/−0
+ CHANGELOG.md view
@@ -0,0 +1,4 @@+# CHANGELOG++## 0.0.1+The first compilable and working version
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2015, s9gf4ult++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of s9gf4ult nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ hset.cabal view
@@ -0,0 +1,30 @@+name: hset+version: 0.0.1+synopsis: Primitive heterogenous read-only set+license: BSD3+license-file: LICENSE+author: s9gf4ult+maintainer: s9gf4ult@gmail.com+category: Data+build-type: Simple+cabal-version: >=1.10+extra-source-files: CHANGELOG.md+homepage: https://bitbucket.org/s9gf4ult/hset+source-repository head+ type: git+ location: git@bitbucket.org:s9gf4ult/hset.git+++library+ default-language: Haskell2010+ hs-source-dirs: src+ exposed-modules: Data.HSet+ build-depends: base >=4.6 && < 5++ default-extensions: DataKinds+ , FlexibleInstances+ , GADTs+ , KindSignatures+ , MultiParamTypeClasses+ , TypeFamilies+ , TypeOperators
+ src/Data/HSet.hs view
@@ -0,0 +1,54 @@+module Data.HSet+ ( HSet(..)+ , HGet(..)+ ) where++data Nat = Z | S Nat++type family Elem (typ :: *) (typs :: [*]) :: Bool where+ Elem typ '[] = 'False+ Elem typ (typ ': typs) = 'True+ Elem typ1 (typ2 ': typs) = Elem typ1 typs++type family Index (typ :: *) (typs :: [*]) :: Nat where+ Index t (t ': ts) = 'Z+ Index t (tt ': ts) = 'S (Index t ts)++-- | Heterogeneous set (list) of elements with unique types. Usefull+-- with MonadReader+data HSet (elems :: [*]) where+ HSNil :: HSet '[]+ HSCons :: ('False ~ (Elem elem elems)) => elem -> HSet elems -> HSet (elem ': elems)++class (i ~ (Index e els)) => HGet els e i where+ -- | Get any data from HSet for you+ hget :: HSet els -> e++instance HGet (e ': els) e 'Z where+ hget (HSCons e _) = e++instance (i ~ (Index e els), ('S i) ~ (Index e (e1 ': els)), HGet els e i) => HGet (e1 ': els) e ('S i) where+ hget (HSCons _ els) = hget els+++----------------------------------------------------------------+-- Tests: if this is compilable then tests done trollface.jpg --++fun :: HSet '[Int, Double, Integer, Float]+fun = HSCons 1+ $ HSCons 2+ $ HSCons 3+ $ HSCons 4+ $ HSNil++funInt :: Int+funInt = hget fun++funDoube :: Double+funDoube = hget fun++funInteger :: Integer+funInteger = hget fun++funFloat :: Float+funFloat = hget fun