packages feed

names (empty) → 0.1

raw patch · 7 files changed

+127/−0 lines, 7 filesdep +basedep +template-haskellsetup-changed

Dependencies added: base, template-haskell

Files

+ LICENSE view
@@ -0,0 +1,18 @@+Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the "Software"),+to deal in the Software without restriction, including without limitation+the rights to use, copy, modify, merge, publish, distribute, sublicense,+and/or sell copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER+DEALINGS IN THE SOFTWARE.+
+ Setup.lhs view
@@ -0,0 +1,4 @@+import Distribution.Simple++main = defaultMain+
+ names.cabal view
@@ -0,0 +1,26 @@+Name:           names+Version:        0.1+Synopsis:       Types that symbolise Names.+Description:    Types that symbolise Names.               +License:        MIT+License-File:   LICENSE+Author:         Julian Fleischer <julian.fleischer@fu-berlin.de>+Maintainer:     Julian Fleischer <julian.fleischer@fu-berlin.de>+Build-Type:     Simple+Cabal-Version:  >= 1.6+Category:       Data, Type System+Stability:      experimental++Library+    Exposed-Modules:    Data.Name,                     +                        Data.Name.TH++    Other-Modules:      Data.Name.Internal.Names,+                        Data.Name.Internal.TH++    Build-Depends:      base >= 4.5 && < 5,+                        template-haskell >= 2.7++    Hs-Source-Dirs:     src++
+ src/Data/Name.hs view
@@ -0,0 +1,13 @@+{-# LANGUAGE Haskell2010+ #-}++module Data.Name (+    (:&),+    module Data.Name.Internal.Names+) where+++import Data.Name.Internal.Names+import Data.Name.Internal.TH++
+ src/Data/Name/Internal/Names.hs view
@@ -0,0 +1,13 @@+{-# LANGUAGE Haskell2010+    , TemplateHaskell+ #-}++module Data.Name.Internal.Names where+++import qualified Data.Name.Internal.TH as TH+++TH.names ['\1' .. '\65535']++
+ src/Data/Name/Internal/TH.hs view
@@ -0,0 +1,42 @@+{-# LANGUAGE Haskell2010+    , TemplateHaskell+    , TypeOperators+ #-}++module Data.Name.Internal.TH (+    name, nameT, names, (:&), toName+) where+++import Numeric (showHex)+import Data.Char (isAlpha, isAlphaNum, isAscii, isUpper, toUpper)+import Language.Haskell.TH+++data a :& b++infixr 3 :&+++nameT :: String -> Q Type+nameT str = return $ foldr f (conT $ last names) (init names)+    where names = map toName str+          conT n = ConT $ mkName ("Data.Name." ++ n)+          f x xs = AppT (AppT (ConT ''(:&)) (conT x)) xs++name :: String -> Q Exp+name str = nameT str >>= return . SigE (VarE 'undefined)++toName c+  | c `elem` ['0'..'9'] = 'D' : [c]+  | isAscii c = if isUpper c then c : "_" else [toUpper c]+  | True = 'U' : padLeft (map toUpper (showHex (fromEnum c) ""))+    where padLeft str = replicate (4 - length str) '0' ++ str++names chars = do+    let alpha    = filter isAlpha chars+        alphaNum = filter isAlphaNum chars+        dataD = \n -> DataD [] (mkName n) [] [] []++    return [ dataD $ toName c | c <- alphaNum ]+
+ src/Data/Name/TH.hs view
@@ -0,0 +1,11 @@+{-# LANGUAGE Haskell2010+ #-}++module Data.Name.TH (+    name, nameT+) where+++import Data.Name.Internal.TH++