haskell

Fast sorting in Haskell

跟風遠走 提交于 2020-01-13 08:44:32
问题 After reading Stack Overflow question Using vectors for performance improvement in Haskell describing a fast in-place quicksort in Haskell, I set myself two goals: Implementing the same algorithm with a median of three to avoid bad performances on pre-sorted vectors; Making a parallel version. Here is the result (some minor pieces have been left for simplicity): import qualified Data.Vector.Unboxed.Mutable as MV import qualified Data.Vector.Generic.Mutable as GM type Vector = MV.IOVector Int

Fast sorting in Haskell

早过忘川 提交于 2020-01-13 08:44:32
问题 After reading Stack Overflow question Using vectors for performance improvement in Haskell describing a fast in-place quicksort in Haskell, I set myself two goals: Implementing the same algorithm with a median of three to avoid bad performances on pre-sorted vectors; Making a parallel version. Here is the result (some minor pieces have been left for simplicity): import qualified Data.Vector.Unboxed.Mutable as MV import qualified Data.Vector.Generic.Mutable as GM type Vector = MV.IOVector Int

A change in my library made it much slower. Profiling isn't helping me. What might be the reason for the slow-down?

怎甘沉沦 提交于 2020-01-13 08:28:08
问题 My Problem, Briefly I made a change to my library, now it's much slower but I can't figure out where it spends all that additional time. Profiling reports are not helping. Please help me figure out what the reason might be. Some Context I made a Redis client-library called Hedis and have a benchmark program for it. Now, I made some internal changes to the library, to clean up the architecture. This caused performance (in Redis-requests per second, as measured by said benchmark) to drop by a

foldr vs foldr1 usage in Haskell

你离开我真会死。 提交于 2020-01-13 08:26:08
问题 If I write: > let xs = [1,5,19,2,-3,5] > foldr max 0 xs 19 > foldr1 max xs 19 And if I write (I know, the initial value is incorrect here for a generic maximum function...): > let maximum' = foldr max 0 > maximum' xs 19 But if I write: > let maximum2' = foldr1 max > maximum2' xs the response is: <interactive>:61:11: Couldn't match expected type `()' with actual type `Integer' Expected type: [()] Actual type: [Integer] In the first argument of maximum2', namely `xs' In the expression: maximum2

Evaluating a function at compile time with Template Haskell

孤街浪徒 提交于 2020-01-13 08:21:31
问题 I am writing a simple HashString class, which is just a string and its hash: data HashString = HashString Int -- ^ hash T.Text -- ^ string! Now I'm trying to generate these at compile time with something like: $(hString "hello, world") :: HashString I want the hash, and the text packing to happen at compile time. How do I do this? Here's what I've tried so far, but I'm not sure if its right, nor am I sure it does everything at compile time: hString :: String -> Q Exp hString s = [| HashString

Haskell: Guidelines for using Strictness

 ̄綄美尐妖づ 提交于 2020-01-13 08:20:34
问题 Is there any recommend guidelines when to use strictness in Haskell ? For example, I was looking on the tagsoup library. They have one of their data structure defined like this: data Tag str = TagOpen str [Attribute str] | TagClose str | TagText str | TagComment str | TagWarning str | TagPosition !Row !Column type Row = Int type Column = Int So on what factor exactly do they decide that TagPosition should be strict ? Are there any recommend guidelines for this ? 回答1: For simple, unstructured

Reading data from Excel in Haskell

淺唱寂寞╮ 提交于 2020-01-13 07:56:09
问题 I would like to get data from .xls files without manually opening Excel. One possibility is to use COM automation. There are the com-1.2.3 and hdirect packages, but I can't find any examples of how to use these packages with Excel. Does anyone have a solution for this? 回答1: With something like this, if your needs are relatively simple, I've found that it's more straightforward to find/write a command line executable that just pulls out a csv from the xls file. Then you invoke that executable

Control.Parallel compile issue in Haskell

若如初见. 提交于 2020-01-13 07:55:09
问题 The compiler is complaining each time on different example applications of parallel Haskell; with this message: Could not find module `Control.Parallel.Strategies' The ghc compiler command: ghc -threaded -i/sudo/dir/par-modules/3 -cpp -DEVAL_STRATEGIES -eventlog --make parFib.hs Same with simpler ghc -O2 --make -threaded parFib.hs What detail am I overlooking? Am I missing some PATH variable. Imports can look like this: module Main where import System # if defined(EVAL_STRATEGIES) import

Simplifying nested Maybe pattern matching

余生长醉 提交于 2020-01-13 05:21:08
问题 I have the following construct in my code: f :: Maybe A -> X f a = case a of Nothing -> x (Just b) -> case b of Nothing -> y (Just c) -> case c of Nothing -> z (Just d) -> d I'm not seeing an obvious way to simplify this instead of using nested maybe functions, which wouldn't make the whole thing look much better. Are there any clever - but still understandable - tricks that would help make this construct more "elegant"? 回答1: UPDATED 2 Monad Either is for you import Data.Maybe (maybe) maybeE

Cabal fails updating of cabal-install

假装没事ソ 提交于 2020-01-13 05:19:07
问题 Every time I install a library, cabal tells me to install a new version of cabal-install. Despite the fact that i run (with apparent success) the procedure that list below, the version of cabal-install remains unchanged. Where I am going wrong? (My OS is Window 7 64-bits) My User PATH is C:\Users\Alberto\AppData\Roaming\cabal\bin System variables: CABAL_DIR = C:\Users\Alberto\AppData\Roaming\cabal BEFORE the update C:\Users\Alberto>cabal -V cabal-install version 1.16.0.2 using version 1.16.0