packages feed

strict-identity (empty) → 0.1.0.0

raw patch · 6 files changed

+245/−0 lines, 6 filesdep +basesetup-changed

Dependencies added: base

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2014, Carter Tazio Schonwald++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 Carter Tazio Schonwald 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
+ changelog.md view
@@ -0,0 +1,4 @@+0.1.0.0+--------++first release of strict-identity
+ readme.md view
@@ -0,0 +1,30 @@+[![Build Status](https://travis-ci.org/cartazio/strict-identity.png?branch=master)](https://travis-ci.org/cartazio/strict-identity)++#About++strict-identity package is meant to make writing nested strict let +expression heavy code a bit more pleasant, for all those High Performance +Haskell lib authors out there.++A simple example of the strict identity monad in action (and working wonderfully)+is the following bit fiddling code, which generates C competitive assembly +on both major GHC backends, -fasm and -fllvm++```haskell+(>>) = unsafeShiftR+(<<) = unsafeShiftL+outerShuffle64A :: Word -> Word +outerShuffle64A !x =+    runStrictIdentity $! do+        x <- return $! ((x .&. 0x00000000FFFF0000) << 16 )+            .|. ((x>>16) .&. 0x00000000FFFF0000) .|. (x .&. 0xFFFF00000000FFFF)+        x <-  return $! ((x .&. 0x0000FF000000FF00 ) <<  8 )+            .|. (x >> 8) .&. 0x0000FF000000FF00 .|. (x  .&. 0xFF0000FFFF0000FF)+        x<-  return $! (( x .&. 0x00F000F000F000F0 ) << 4 )+            .|. (x >> 4) .&. 0x00F000F000F000F0 .|. (x .&. 0xF00FF00FF00FF00F )+        x<-   return $!((x .&.  0x0C0C0C0C0C0C0C0C )<< 2 )+            .|. (x >> 2) .&. 0x0C0C0C0C0C0C0C0C .|.( x .&. 0xC3C3C3C3C3C3C3C3)+        x<-   return $! ( (x .&. 0x2222222222222222)  << 1 ) +            .|. (x>> 1) .&. 0x2222222222222222 .|. (x .&. 0x9999999999999999)+        return x+```
+ src/Control/Monad/StrictIdentity.hs view
@@ -0,0 +1,101 @@+{- |+Module      :  Control.Monad.StrictIdentity+Copyright   :  (c) Carter Schonwald 2013+License     :  BSD3, see license file+ +Maintainer  :  libraries@haskell.org+Stability   :  experimental+Portability :  portable+-}+{-# LANGUAGE BangPatterns #-}+ + +module Control.Monad.StrictIdentity (+    StrictIdentity(..),+    runStrictIdentity)+    where+ ++import Control.Monad.Fix +import Control.Applicative+++{- | 'StrictIdentity' is a newtype wrapper for a given type 'a' that +satisfies the 'Functor', 'Applicative', and 'Monad' laws  when restricted to+terminating strict computations. ++The typical use case is to provide a light weight strict nested +let notation for code that otherwise must use nested case expressions+as a proxy for a strict let.++the general pattern is to write code of the form++@+foo f h g x y z = runStrictIdentity $! do+    w <- return $! f x y+    j <- return $! h w z+    res <- return $! g w j+    return res+@++An example usage of 'StrictIdentity' that compiles to assembly +comparable to C is the following:++@+(>>) = unsafeShiftR+(<<) = unsafeShiftL+outerShuffle64A :: Word -> Word +outerShuffle64A !x =+    runStrictIdentity $! do+        x <- return $! ((x .&. 0x00000000FFFF0000) << 16 )+            .|. ((x>>16) .&. 0x00000000FFFF0000) .|. (x .&. 0xFFFF00000000FFFF)+        x <-  return $! ((x .&. 0x0000FF000000FF00 ) <<  8 )+            .|. (x >> 8) .&. 0x0000FF000000FF00 .|. (x  .&. 0xFF0000FFFF0000FF)+        x<-  return $! (( x .&. 0x00F000F000F000F0 ) << 4 )+            .|. (x >> 4) .&. 0x00F000F000F000F0 .|. (x .&. 0xF00FF00FF00FF00F )+        x<-   return $!((x .&.  0x0C0C0C0C0C0C0C0C )<< 2 )+            .|. (x >> 2) .&. 0x0C0C0C0C0C0C0C0C .|.( x .&. 0xC3C3C3C3C3C3C3C3)+        x<-   return $! ( (x .&. 0x2222222222222222)  << 1 ) +            .|. (x>> 1) .&. 0x2222222222222222 .|. (x .&. 0x9999999999999999)+        return x+@+++-}+ +newtype StrictIdentity a =  StrictIdentity {runStrictIdentity_ :: a }+ +-- | 'runStrictIdentity' unwraps a value of type  @'StrictIdentity' ty@  into a value of type @ty@,  strictly.+runStrictIdentity :: StrictIdentity a -> a +runStrictIdentity !ma = case runStrictIdentity_ $! ma of +                            !res -> res  +{-# INLINE  runStrictIdentity #-} +++instance Applicative StrictIdentity where+    {-# INLINE pure #-}+    pure = return +    {-# INLINE (<*>) #-}+    (<*>) a b = do   f <- a ; v <- b ; return $! (f $! v)+    -- ap a b = liftM2 id a b  =  do  f <- a ; v<- b ; return ((id) )++++ +instance Functor StrictIdentity where+    {-# INLINE fmap  #-}+    fmap !f !m = StrictIdentity $! (f $! (runStrictIdentity m))+ +instance Monad StrictIdentity where+    {-# INLINE return  #-}+    return !a = StrictIdentity $! a+    {-# INLINE  (>>=) #-}+    (!m) >>= (!k)  = k $! runStrictIdentity  m    + --StrictIdentity m >>= k  =  k $! m+instance MonadFix StrictIdentity where+    {-# INLINE mfix  #-}+    mfix !f = StrictIdentity $! (fix  (runStrictIdentity . f))    ++++
+ strict-identity.cabal view
@@ -0,0 +1,78 @@+-- Initial strict-identity.cabal generated by cabal init.  For further +-- documentation, see http://haskell.org/cabal/users-guide/++-- The name of the package.+name:                strict-identity++-- The package version.  See the Haskell package versioning policy (PVP) +-- for standards guiding when and how versions should be incremented.+-- http://www.haskell.org/haskellwiki/Package_versioning_policy+-- PVP summary:      +-+------- breaking API changes+--                   | | +----- non-breaking API additions+--                   | | | +--- code changes with no API change+version:             0.1.0.0++-- A short (one-line) description of the package.+synopsis:            Strict Identity Monad, handy for writing fast code!++-- A longer description of the package.+description:  strict Identity monad for writing strict performant code sanely++-- URL for the project homepage or repository.+homepage:            https://github.com/cartazio/strict-identity++++-- The license under which the package is released.+license:             BSD3++-- The file containing the license text.+license-file:        LICENSE++-- The package author(s).+author:              Carter Tazio Schonwald++-- An email address to which users can send suggestions, bug reports, and +-- patches.+maintainer:          carter at wellposed.com++-- A copyright notice.+-- copyright:           ++category:            Control++build-type:          Simple++-- Extra files to be distributed with the package, such as examples or a +-- README.+-- extra-source-files:  ++-- Constraint on the version of Cabal needed to build this package.+cabal-version:       >=1.10++extra-source-files: changelog.md +                    readme.md ++library+  -- Modules exported by the library.+  exposed-modules:     Control.Monad.StrictIdentity++  -- Modules included in this library but not exported.+  -- other-modules:       +  ghc-options: -Wall  +  -- LANGUAGE extensions used by modules in this package.+  other-extensions:    BangPatterns+  +  -- Other library packages from which modules are imported.+  build-depends:       base >=4.3 && <4.8+  +  -- Directories containing source files.+  hs-source-dirs:      src+  +  -- Base language which the package is written in.+  default-language:    Haskell2010++source-repository head+  type: git+  location: http://github.com/cartazio/strict-identity.git  +