recentpopularlog in


« earlier   
Standard types, classes and related functions
Basic data types
Basic type classes
Numeric types
Numeric type classes
Numeric functions
Semigroups and Monoids
Monads and functors
Folds and traversals
Miscellaneous functions
List operations
Special folds
Building lists
Infinite lists
Searching lists
Zipping and unzipping lists
Functions on strings
Converting to and from String
Converting to String
Converting from String
Basic Input and output
Simple I/O operations
Output functions
Input functions
Exception handling in the I/O monad
haskell  standard_library  documentation 
17 hours ago by dicewitch
Beating C with 80 lines of Haskell: wc
import Types
import Control.Monad
import Data.Traversable
import Data.Bits
import GHC.Conc (numCapabilities)
import Control.Concurrent.Async
import Data.Foldable
import System.IO
import System.Posix.Files
import qualified Data.ByteString.Lazy.Char8 as BL
import Data.ByteString.Internal (c2w)
import GHC.IO.Handle

multiCoreCount :: FilePath -> IO Counts
multiCoreCount fp = do
putStrLn ("Using available cores: " <> show numCapabilities)
size <- fromIntegral . fileSize <$> getFileStatus fp
let chunkSize = fromIntegral (size `div` numCapabilities)
fold <$!> (forConcurrently [0..numCapabilities-1] $ \n -> do
-- Take all remaining bytes on the last capability due to integer division anomolies
let limiter = if n == numCapabilities - 1
then id
else BL.take (fromIntegral chunkSize)
let offset = fromIntegral (n * chunkSize)
fileHandle <- openBinaryFile fp ReadMode
hSeek fileHandle AbsoluteSeek offset
countBytes . limiter <$!> BL.hGetContents fileHandle)
{-# INLINE handleSplitUTF #-}

countBytes :: BL.ByteString -> Counts
countBytes = BL.foldl' (\a b -> a <> countChar b) mempty
{-# INLINE countBytes #-}


module Streaming where

import Types
import Data.Traversable
import GHC.Conc (numCapabilities)
import System.IO (openFile, IOMode(..))
import qualified Streamly as S
import qualified Streamly.Data.String as S
import qualified Streamly.Prelude as S
import qualified Streamly.Internal.Memory.Array as A
import qualified Streamly.Internal.FileSystem.Handle as FH

streamingBytestream :: FilePath -> IO Counts
streamingBytestream fp = do
src <- openFile fp ReadMode
S.foldl' mappend mempty
$ S.aheadly
$ S.maxThreads numCapabilities
$ S.mapM countBytes
$ FH.toStreamArraysOf 1024000 src
countBytes =
S.foldl' (\acc c -> acc <> countByte c) mempty
. S.decodeChar8
. A.toStream

{-# INLINE streamingBytestream #-}
haskell  performance  optimization 
yesterday by some_hren
The Joy of Haskell
A manual for happy Haskelling.
ebook  haskell 
2 days ago by HusseinMorsy
Nix Integration for Stack —
You may want to build your Haskell application with #Nix even if you did start with #Stack. #Stack has support for building with #Nix. ...
haskell  nix  stack 
2 days ago by ianweatherhogg
[ANN] typelits-printf: type-safe polymorphic printf using ghc typelits in

> printf @"You have %.2f dollar…
haskell  from twitter_favs
2 days ago by tjweir
Qualified names - HaskellWiki

Please make more use of the qualified ID syntax! Haskell has had this feature for quite some time now, but I hardly ever see it used ...

Especially in modules that import a lot of other modules, it's

easier to recognize an identifier if it's prefixed by a module ID rather than look through all the imported modules, and
easier to modify a module if all you need to do to pull in a new value is to use it, rather than scrolling up, and adding it to the list of identifiers in something like import M (...).

This is standard practice in both SML and Ocaml. (In fact, I would rather not have to declare things like import qualified M at all ...)

If you have a long module name, declare an alias:

`import qualified LongModuleName as LMN`

BTW, another advantage of this syntax is that identifiers within their own defining module get shorter, and consequently it gets easier to read. For example, don't define addToFM; define addTo and then do import FiniteMap as FM. Sometimes this means having to hide Prelude identifiers and qualify them at use (as it would be with lookupFM in GHC's FiniteMap module) but is that such a great price to pay...?

Please. Pretty please? Pretty please with sugar on top?


P.S. Except infix combinators. These are ugly when you qualify them.
haskell  reference  namespace  packages 
2 days ago by dicewitch

Copy this bookmark:

to read