haskell

Conduit - Multiple output file within the pipeline

强颜欢笑 提交于 2020-01-01 09:09:07
问题 I'm writing a programme where an input file is split into multiple files (Shamir's Secret Sharing Scheme). Here's the pipeline I'm imagining: source: use Conduit.Binary.sourceFile to read from the input conduit: Takes a ByteString, produces [ByteString] sink: Takes [ByteString] from the conduit, and write each ByteString (in [ByteString]) to their corresponding file. (say if our input [ByteString] is called bsl, then bsl !! 0 will be written to file 0, bsl !! 1 to file 1 and so on) I found a

Can you make an instance of a class not for a type but for a whole class in Haskell?

你说的曾经没有我的故事 提交于 2020-01-01 09:04:13
问题 Suppose I want to make all numbers an instance of Monoid . Instead of having to create an instance for each Num like this: instance Monoid Int where mappend = (+) mempty = 0 instance Monoid Float where mappend = (+) mempty = 0.0 -- etc Is there something like this? instance Num t => Monoid t where mappend = (+) mempty = 0 Edit Some are answering with GHC extensions and warning about the potential issues; I found that informative, but I think I will stick with Sum , Product and whatever coerce

Mark block based on indentation level in Vim

梦想的初衷 提交于 2020-01-01 09:03:18
问题 Is it possible to mark a block in Vim based on the indentation already in place? Similarly to v{ . It would be extremely useful for programming languages with whitespace-sensitive syntax (like Haskell and Python). For example mark everything between the first let and return in this function: checkArg (com:arg) s d ns | com == "add-source " = do let s' = v ++ s lift $ saveLinks s' return (s', d) | com == "remove-source" = do let s' = filter (not . hasWord str) s lift $ saveLinks s' return (s',

What are the differences between inline-c and language-c-inline?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 08:56:28
问题 I've been briefly looking into quasi-quotation libraries for Haskell. These libraries allow Haskell to integrate with other languages. For integrating with C, there appears to be two packages with similar functionality: inline-c language-c-inline (which uses language-c-quote) As I'm looking to build a quasi-quotation library of my own, I'm interested in design choices, API differences, performance etc. The only difference I'm aware of is that language-c-quote supports C and Objective-C,

How does HOpenGL behave with regards to other threads and TChans in Haskell?

↘锁芯ラ 提交于 2020-01-01 08:53:32
问题 I'm doing some proof-of-concept work for a fairly complex video game I'd like to write in Haskell using the HOpenGL library. I started by writing a module that implements client-server event based communication. My problem appears when I try to hook it up to a simple program to draw clicks on the screen. The event library uses a list of TChans made into a priority queue for communication. It returns an "out" queue and an "in" queue corresponding to server-bound and client-bound messages.

Load a new package in ghci using stack

Deadly 提交于 2020-01-01 08:47:29
问题 Is there a way to load a package(s) using Stack in GHCI and play around with it ? So, that when the ghci is loaded, we can import the modules and see it's type signature, etc. 回答1: For the packages present in Stackage, $ stack ghci --package unix-time And this will give you a repl with the package unix-time loaded in it: Run from outside a project, using implicit global project config Using resolver: lts-6.14 from implicit global project's config file: /home/sibi/.stack/global-project/stack

Load a new package in ghci using stack

会有一股神秘感。 提交于 2020-01-01 08:47:03
问题 Is there a way to load a package(s) using Stack in GHCI and play around with it ? So, that when the ghci is loaded, we can import the modules and see it's type signature, etc. 回答1: For the packages present in Stackage, $ stack ghci --package unix-time And this will give you a repl with the package unix-time loaded in it: Run from outside a project, using implicit global project config Using resolver: lts-6.14 from implicit global project's config file: /home/sibi/.stack/global-project/stack

What's going on in this type signature? (Vector.Mutable modifiers in Haskell)

杀马特。学长 韩版系。学妹 提交于 2020-01-01 08:45:59
问题 Mutable vectors in Haskell have three element-level mutators: read :: PrimMonad m => MVector (PrimState m) a -> Int -> m a write :: PrimMonad m => MVector (PrimState m) a -> Int -> a -> m () swap :: PrimMonad m => MVector (PrimState m) a -> Int -> Int -> m () Now I can use these fine -- import Data.Vector import Data.Vector.Mutable import Control.Monad.ST import Control.Monad.Primitive incrAt :: Vector Double -> Int -> Vector Double incrAt vec i = runST $ do mvec <- thaw vec oldval <- read

What's going on in this type signature? (Vector.Mutable modifiers in Haskell)

拈花ヽ惹草 提交于 2020-01-01 08:45:27
问题 Mutable vectors in Haskell have three element-level mutators: read :: PrimMonad m => MVector (PrimState m) a -> Int -> m a write :: PrimMonad m => MVector (PrimState m) a -> Int -> a -> m () swap :: PrimMonad m => MVector (PrimState m) a -> Int -> Int -> m () Now I can use these fine -- import Data.Vector import Data.Vector.Mutable import Control.Monad.ST import Control.Monad.Primitive incrAt :: Vector Double -> Int -> Vector Double incrAt vec i = runST $ do mvec <- thaw vec oldval <- read

Stack's package.yaml vs stack.yaml

五迷三道 提交于 2020-01-01 08:42:51
问题 Stack has supported hpack's package.yaml configuration files since at least around this commit, as far as I can tell, but there's not much documentation about the differences between it and the stack.yaml file. One of the few links I've found talking about it is this documentation, where it says: package.yaml is a file format supported by hpack. It adds some niceties on top of cabal. For example, hpack has YAML syntax support and will automatically generate of exposed-modules lists. However,