packages feed

HsTools (empty) → 0.0.1.1

raw patch · 6 files changed

+161/−0 lines, 6 filesdep +basedep +ghc-primsetup-changed

Dependencies added: base, ghc-prim

Files

+ Data/Ix/List.hs view
@@ -0,0 +1,46 @@++-- | Transform lists of bounded enumerables into an index. A version for lists+-- of different sizes exists as well.++module Data.Ix.List where++import Control.Exception (assert)+++-- | transform a list of bounded enumerables into an integer index. the first+-- character will be least significant, the last most significant++list2idx :: (Enum a, Bounded a) => [a] -> Int+list2idx xs = assert (not $ null xs) l2i 1 xs where+  l2i k [x]    = k * fromEnum x+  l2i k (x:xs) = k * fromEnum x + l2i (k * c) xs where+    c = fromEnum (maxBound `asTypeOf` x) - fromEnum (minBound `asTypeOf` x) + 1+{-# INLINE list2idx #-}++-- | Version for lists of different sizes.++listAll2idx :: (Enum a, Bounded a) => [a] -> Int+listAll2idx [] = 0+listAll2idx xs = l2i 1 xs where+  l2i k [x]    = k * (fromEnum x +1)+  l2i k (x:xs) = k * (fromEnum x +1) + l2i (k * c) xs where+    c = fromEnum (maxBound `asTypeOf` x) - fromEnum (minBound `asTypeOf` x) + 2+{-# INLINE listAll2idx #-}++++++-- | same as above, but now the list is bounded (hence _b_oundedlist) by the+-- user.++-- TODO maybe assert that (fromEnum x >= emin) && (fromEnum x <= emax)++blist2idx :: (Enum a, Bounded a) => (a,a) -> [a] -> Int+blist2idx (bmin,bmax) xs = assert (not $ null xs) $ l2i 1 xs where+  l2i k [x]    = k * (fromEnum x - emin)+  l2i k (x:xs) = k * (fromEnum x - emin) + l2i (k*c) xs where+    c = emax - emin + 1+  emin = fromEnum bmin+  emax = fromEnum bmax+{-# INLINE blist2idx #-}
+ Data/Ix/Tuple.hs view
@@ -0,0 +1,35 @@++{-# LANGUAGE StandaloneDeriving, TypeSynonymInstances #-}+module Data.Ix.Tuple where++import Data.Ix+import GHC.Tuple++deriving instance (Ix a, Ix b, Ix c, Ix d, Ix e, Ix f) => Ix (a,b,c,d,e,f)+deriving instance (Ix a, Ix b, Ix c, Ix d, Ix e, Ix f, Ix g) => Ix (a,b,c,d,e,f,g)+deriving instance (Ix a, Ix b, Ix c, Ix d, Ix e, Ix f, Ix g, Ix h) => Ix (a,b,c,d,e,f,g,h)++-- how it would be done manually+{-+instance  (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5, Ix a6) => Ix (a1,a2,a3,a4,a5,a6)  where+    range ((l1,l2,l3,l4,l5,l6),(u1,u2,u3,u4,u5,u6)) =+      [(i1,i2,i3,i4,i5,i6) | i1 <- range (l1,u1),+                             i2 <- range (l2,u2),+                             i3 <- range (l3,u3),+                             i4 <- range (l4,u4),+                             i5 <- range (l5,u5),+                             i6 <- range (l6,u6)]++    unsafeIndex ((l1,l2,l3,l4,l5,l6),(u1,u2,u3,u4,u5,u6)) (i1,i2,i3,i4,i5,i6) =+      unsafeIndex (l6,u6) i6 + unsafeRangeSize (l6,u6) * (+      unsafeIndex (l5,u5) i5 + unsafeRangeSize (l5,u5) * (+      unsafeIndex (l4,u4) i4 + unsafeRangeSize (l4,u4) * (+      unsafeIndex (l3,u3) i3 + unsafeRangeSize (l3,u3) * (+      unsafeIndex (l2,u2) i2 + unsafeRangeSize (l2,u2) * (+      unsafeIndex (l1,u1) i1)))))++    inRange ((l1,l2,l3,l4,l5,l6),(u1,u2,u3,u4,u5,u6)) (i1,i2,i3,i4,i5,i6) =+      inRange (l1,u1) i1 && inRange (l2,u2) i2 &&+      inRange (l3,u3) i3 && inRange (l4,u4) i4 &&+      inRange (l5,u5) i5 && inRange (l6,u6) i6+-}
+ Debug/Trace/Tools.hs view
@@ -0,0 +1,20 @@++module Debug.Trace.Tools where++import Debug.Trace++++-- | inline output a variable++traceVal msg x = trace (if msg /= "" then msg ++ " " ++ show x else show x) x++++-- | conditional tracing++traceIf cnd msg x = if cnd then trace msg x else x++-- | conditional inline tracing++traceIfVal cnd msg x = if cnd then traceVal msg x else x
+ HsTools.cabal view
@@ -0,0 +1,28 @@+name:           HsTools+version:        0.0.1.1+author:         Christian Hoener zu Siederdissen+maintainer:     choener@tbi.univie.ac.at+copyright:      Christian Hoener zu Siederdissen, 2010+category:       Generic+synopsis:       Haskell helper functions+license:        BSD3+license-file:   LICENSE+build-type:     Simple+stability:      experimental+cabal-version:  >= 1.4.0+description:+                Helper functions for a lot of different libraries. (unstable+                library!)++library+  build-depends:+    base >= 4 && < 5,+    ghc-prim++  exposed-modules:+    Data.Ix.Tuple,+    Data.Ix.List,+    Debug.Trace.Tools++  ghc-options:+    -O2
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Christian Hoener zu Siederdissen 2010++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 Christian Hoener zu Siederdissen 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