packages feed

binary-literal-qq (empty) → 1.0

raw patch · 4 files changed

+87/−0 lines, 4 filesdep +basedep +template-haskellsetup-changed

Dependencies added: base, template-haskell

Files

+ LICENSE view
@@ -0,0 +1,27 @@+Copyright (c) 2012 Mathieu Boespflug++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:+1. Redistributions of source code must retain the above copyright+   notice, this list of conditions and the following disclaimer.+2. 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.+3. Neither the name of the author nor the names of his contributors+   may be used to endorse or promote products derived from this software+   without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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.
+ Language/Literals/Binary.hs view
@@ -0,0 +1,32 @@+-- | This module exports a quasiquoter for binary integer literals.+--+-- Example usage:+--+-- @+-- import Language.Literals.Binary+-- import Data.Word+--+-- not :: Word32 -> Word32+-- not [b| 0 |] = [b| 1 |]+-- not [b| 1 |] = [b| 0 |]+-- @++module Language.Literals.Binary where++import Language.Haskell.TH.Quote+import Language.Haskell.TH.Syntax+import Data.Bits+++b = QuasiQuoter+  { quoteExp  = return . LitE . IntegerL . readBinary+  , quotePat  = return . LitP . IntegerL . readBinary+  , quoteType = error "No quasiquoter for types."+  , quoteDec  = error "No quasiquoter for declarations." }++readBinary :: String -> Integer+readBinary = foldl f 0 where+  f x '0' = shift x 1+  f x '1' = shift x 1 + 1+  f x ' ' = x+  f x _   = error "Not a valid binary literal."
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ binary-literal-qq.cabal view
@@ -0,0 +1,25 @@+name:           binary-literal-qq+version:        1.0+author:         Mathieu Boespflug+maintainer:     Mathieu Boespflug <mboes@tweag.net>+copyright:      © 2012 Mathieu Boespflug+synopsis:       Extends Haskell with binary literals.+description:+    The Haskell'98 and Haskell'2010 standards define decimal, octal+    and hexadecimal integer literals. Binary literals are+    conspicuously missing. Here's a quasiquoter to remedy the+    situation.+category:       Language+license:        BSD3+license-file:   LICENSE+cabal-version:  >= 1.9.2+build-type:     Simple++source-repository head+  type:     git+  location: git://github.com/mboes/binary-literal-qq++library+  build-depends:   base == 4.*, template-haskell >= 2.5+  exposed-modules: Language.Literals.Binary+  ghc-options:     -W -fno-warn-incomplete-patterns -fno-warn-unused-matches