Re: [Haskell-cafe] Using lenses

2013-10-03 Thread Nicolas Trangez
Simon, On Thu, 2013-10-03 at 08:07 +, Simon Peyton-Jones wrote: If you are using the lens library yourself, could you spare a few minutes to tell me how you are using it? I'm not a heavy 'lens'-user (yet), and this might not be the most pretty use-case from a theoretic point of view, but

Re: [Haskell-cafe] Proposal: Partitionable goes somewhere + containers instances

2013-09-29 Thread Nicolas Trangez
I'd think partition :: t - Either t (t, t) might be more suited then... Nicolas On Sep 29, 2013 1:21 AM, Ryan Newton rrnew...@gmail.com wrote: subject change On Sun, Sep 29, 2013 at 3:31 AM, Mike Izbicki m...@izbicki.me wrote: I've got a Partitionable class that I've been using for this

Re: [Haskell-cafe] Bytestring map/zipWith rationale

2013-09-12 Thread Nicolas Trangez
I did use that a couple of times (`xor`ing 2 ByteStrings together), and was surprised by the omission back then, but IIRC (can't validate now), there's a specialised zipWith (as proposed) in the module (with some other name, obviously), which is not exported, but used when you 'pack' the result of

[Haskell-cafe] Traversals of monomorphic containers (was: Re: mapM_ for bytestring)

2013-09-02 Thread Nicolas Trangez
# Redirected to haskell-cafe On Sun, 2013-09-01 at 14:58 +0400, Artyom Kazak wrote: Would this be an appropriate place to propose adding mapM_ (and then possibly mapM) to bytestring library? Was it suggested before? If yes, why was it rejected? This got me wondering: there are several

Re: [Haskell-cafe] Proposal: Generic conditions for 'if' and 'case'

2013-09-02 Thread Nicolas Trangez
On Sun, 2013-09-01 at 15:51 -0700, Wvv wrote: I think it is an old idea, but nevertheless. Now we have next functions: if (a :: Bool) then x else y case b of a1 :: Bool - x1 a2 :: Bool - x2 ... Let we have generic conditions for 'if' and 'case': class Boolean a where toBool

Re: [Haskell-cafe] Proposal: Generic conditions for 'if' and 'case'

2013-09-01 Thread Nicolas Trangez
I didn't test it, but you might want to look into the 'rebindable syntax' extension and its 'ifThenElse' feature. Nicolas On Sep 2, 2013 12:51 AM, Wvv vite...@rambler.ru wrote: I think it is an old idea, but nevertheless. Now we have next functions: if (a :: Bool) then x else y case b of

[Haskell-cafe] TypeLits Typeable

2013-08-24 Thread Nicolas Trangez
Hello Cafe, I was playing around with TypeLits in combination with Typeable (using GHC 7.7.7.20130812 FWIW), but was surprised to find Symbols aren't Typeable, and as such the following doesn't work. Is this intentional, or am I missing something? Thanks, Nicolas {-# LANGUAGE DataKinds,

Re: [Haskell-cafe] Yet Another Forkable Class

2013-08-23 Thread Nicolas Trangez
On Fri, 2013-08-23 at 08:06 +, o...@okmij.org wrote: It will arbitrarily pick the first match in the former and fail to compile in the latter case. Of course we can have duplicate layers. In that case, the dynamically closest handler wins -- which sounds about right (think of reset

[Haskell-cafe] Stuck on design problem

2013-05-20 Thread Nicolas Trangez
All, Since I'm stuck on a coding problem and can't figure out how to proceed, I decided to call for help. I'm unable to get some code to typecheck, so maybe I'm missing something obvious on the implementation side, or more likely the design is completely wrong. Here's the idea: I have some code

[Haskell-cafe] Failure deriving MonadRWS when using a type-family for the State part

2013-05-20 Thread Nicolas Trangez
All, The following code results in a compilation error (I tried GHC 7.4.1 a 7.7.20130430 build): {-# LANGUAGE TypeFamilies, GeneralizedNewtypeDeriving, StandaloneDeriving #-} module Main where import Control.Applicative import Control.Monad.RWS data C = C data E = E

Re: [Haskell-cafe] Stuck on design problem

2013-05-20 Thread Nicolas Trangez
! Nicolas 20.05.2013, 15:36, Nicolas Trangez nico...@incubaid.com: All, Since I'm stuck on a coding problem and can't figure out how to proceed, I decided to call for help. I'm unable to get some code to typecheck, so maybe I'm missing something obvious on the implementation side

Re: [Haskell-cafe] Stuck on design problem

2013-05-20 Thread Nicolas Trangez
Adam, On Mon, 2013-05-20 at 13:37 +0100, Adam Gundry wrote: Hi Nicolas, Your design doesn't look too unreasonable, though I haven't looked at in detail. I do have a quick observation regarding the implementation that I hope might help. Your gist defines class MonadLog m a where

Re: [Haskell-cafe] Failure deriving MonadRWS when using a type-family for the State part

2013-05-20 Thread Nicolas Trangez
.hs:14:20 and λ :t undefined :: F S undefined :: F S :: T -} Nicolas On Tue, 2013-05-21 at 00:08 +0200, Nicolas Trangez wrote: All, The following code results in a compilation error (I tried GHC 7.4.1 a 7.7.20130430 build): {-# LANGUAGE TypeFamilies

Re: [Haskell-cafe] Backward compatibility

2013-05-03 Thread Nicolas Trangez
On Fri, 2013-05-03 at 10:40 -0700, Hilco Wijbenga wrote: On 3 May 2013 09:44, Niklas Hambüchen m...@nh2.me wrote: While I certainly enjoy the discussion, how about addressing one of the original problems: On 02/05/13 13:27, Adrian May wrote: I just tried to use Flippi. It broke because

Re: [Haskell-cafe] [extension]syntactic sugar for maps

2013-03-27 Thread Nicolas Trangez
On Wed, 2013-03-27 at 21:30 +0200, Răzvan Rotaru wrote: I am terribly missing some syntactic sugar for maps (associative data structures) in Haskell. I find myself using them more than any other data structure, and I think there is no big deal in adding some sugar for this to the language. I

Re: [Haskell-cafe] Streaming bytes and performance

2013-03-19 Thread Nicolas Trangez
On Tue, 2013-03-19 at 20:32 +, Don Stewart wrote: Oh, I forgot the technique of inlining the lazy bytestring chunks, and processing each chunk seperately. $ time ./fast 4166680 ./fast 1.25s user 0.07s system 99% cpu 1.325 total Essentially inline Lazy.foldlChunks and specializes is

Re: [Haskell-cafe] The state of binary (de)serialization

2013-02-28 Thread Nicolas Trangez
On Thu, 2013-02-28 at 01:22 -0800, wren ng thornton wrote: On 2/27/13 2:17 AM, Vincent Hanquez wrote: Two major problems of lazy bytestrings is that: * you can't pass it to a C bindings easily. * doing IO with it without rewriting the chunks, can sometimes (depending how the lazy

Re: [Haskell-cafe] The state of binary (de)serialization

2013-02-28 Thread Nicolas Trangez
On Mon, 2013-02-25 at 11:59 -0800, Johan Tibell wrote: On Mon, Feb 25, 2013 at 4:30 AM, Nicolas Trangez nico...@incubaid.comwrote: - cereal supports chunk-based 'partial' parsing (runGetPartial). It looks like support for this is introduced in recent versions of 'binary' as well

Re: [Haskell-cafe] The state of binary (de)serialization

2013-02-28 Thread Nicolas Trangez
On Wed, 2013-02-27 at 07:49 +0100, Vincent Hanquez wrote: On Mon, Feb 25, 2013 at 01:30:40PM +0100, Nicolas Trangez wrote: ... I've been looking at the same thing lately, and i've been quite surprised, to say the least, by the usual go-to packages (cereal, binary). Performance wise

[Haskell-cafe] The state of binary (de)serialization

2013-02-25 Thread Nicolas Trangez
All, In order to implement some network protocol clients recently, I needed binary serialization of commands and deserialization of responses ('Command - ByteString' and 'ByteString - Response' functions, preferably for both strict as well as lazy ByteStrings). My go-to packages have always been

Re: [Haskell-cafe] performance question

2013-02-13 Thread Nicolas Trangez
On Wed, 2013-02-13 at 08:39 -0800, David Thomas wrote: One way in which regexps are foreign to Haskell-think is that, if they break, they generally break at run-time. This could be ameliorated with template haskell Care to elaborate on the ameliorate using TH part? I figure regexes would be

Re: [Haskell-cafe] Layer on a layer of record syntax in the type synonym?

2012-12-21 Thread Nicolas Trangez
On Fri, 2012-12-21 at 04:36 -0900, Christopher Howard wrote: Using a simple type I gave earlier from my monadic type question... code: data Socket3 a b c = Socket3 a b c deriving (Show) Is it possible somehow to layer on record syntax onto a synonym of the type?

[Haskell-cafe] (L)GPL libraries Haskell/GHC (was: Re: ANNOUNCE: tie-knot library)

2012-12-11 Thread Nicolas Trangez
Note: IANAL On Tue, 2012-12-11 at 17:45 -0800, David Thomas wrote: On Tue, Dec 11, 2012 at 5:35 PM, Brandon Allbery allber...@gmail.comwrote: (Oddly enough, GPL is not the only open source license.) There was no implication to the contrary. It was stated that BSD is a *weaker* license -

[Haskell-cafe] ANN: zeromq3-conduit, Conduit bindings for zeromq3-haskell

2012-11-30 Thread Nicolas Trangez
Hi, I published zeromq3-conduit, a small library which facilitates using zeromq3-haskell, a binding for ZeroMQ 3.x, in a Conduit-based application. The 'examples' folder in the source repository contains ports of the zeromq3-haskell examples. The library also contains a module which might ease

Re: [Haskell-cafe] Conduit and pipelined protocol processing using a threadpool

2012-11-28 Thread Nicolas Trangez
On Wed, 2012-11-28 at 09:17 +0200, Michael Snoyman wrote: On Tue, Nov 27, 2012 at 7:25 PM, Nicolas Trangez nico...@incubaid.com wrote: Michael, On Tue, 2012-11-27 at 17:14 +0200, Michael Snoyman wrote: I think the stm-conduit package[1] may be helpful

[Haskell-cafe] Conduit and pipelined protocol processing using a threadpool

2012-11-27 Thread Nicolas Trangez
All, I've written a library to implement servers for some protocol using Conduit (I'll announce more details later). The protocol supports pipelining, i.e. a client can send a 'command' which contains some opaque 'handle' chosen by the client, the server processes this command, then returns some

Re: [Haskell-cafe] Conduit and pipelined protocol processing using a threadpool

2012-11-27 Thread Nicolas Trangez
Michael, On Tue, 2012-11-27 at 17:14 +0200, Michael Snoyman wrote: I think the stm-conduit package[1] may be helpful for this use case. Each time you get a new command, you can fork a thread and give it the TBMChan to write to, and you can use sourceTBMChan to get a source to send to the

[Haskell-cafe] Custom Enum instance with non-consecutive indices

2012-11-17 Thread Nicolas Trangez
All, I've been working on a server implementation of an existing networking protocol. The protocol uses magic constants in some places (e.g. to tag message types), as well as bitfields, or a combination of both packed in a single value. I created data types for both the identifiers as well as

Re: [Haskell-cafe] Custom Enum instance with non-consecutive indices

2012-11-17 Thread Nicolas Trangez
On Sat, 2012-11-17 at 16:52 +0200, Roman Cheplyaka wrote: Hi Nicolas, The simplest approach would be to use the standard (derived) Enum instance that would be used for enumerations (like [Flag1..]), and have your own functions to convert to/from magic constants. Sure, but that kind-of

Re: [Haskell-cafe] Custom Enum instance with non-consecutive indices

2012-11-17 Thread Nicolas Trangez
On Sat, 2012-11-17 at 16:27 +0100, Herbert Valerio Riedel wrote: what do you hope to gain from making your flags type an instance of the Enum class? Among others, the ability to list all flags using [Flag1 ..] How is this handled for libraries wrapping C libs which use some bitset structure?

Re: [Haskell-cafe] performance issues with popCount

2012-09-08 Thread Nicolas Trangez
On Fri, 2012-09-07 at 15:55 -0700, Johan Tibell wrote: On Fri, Sep 7, 2012 at 4:54 AM, Nicolas Trangez nico...@incubaid.com wrote: On Thu, 2012-09-06 at 12:07 -0700, Johan Tibell wrote: Have a look at the popCount implementation for e.g. Int, which are written in C and called through

Re: [Haskell-cafe] performance issues with popCount

2012-09-07 Thread Nicolas Trangez
On Thu, 2012-09-06 at 12:07 -0700, Johan Tibell wrote: Have a look at the popCount implementation for e.g. Int, which are written in C and called through the FFI: https://github.com/ghc/packages-ghc-prim/blob/master/cbits/popcnt.c Out of interest: isn't this compiled into the popCnt# primop

[Haskell-cafe] Vector: blit'ing a source into a destination

2012-09-02 Thread Nicolas Trangez
All, For some code I need to alter an (unboxed or storable) vector by blit'ing (copying) data from another (smaller) vector into it, overwriting the existing data. I couldn't find a function for this in the vector API, so I hacked something up which cuts the jobs (see below), but it feels really

[Haskell-cafe] Memory corruption issues when using newAlignedPinnedByteArray, GC kicking in?

2012-07-10 Thread Nicolas Trangez
All, While working on my vector-simd library, I noticed somehow memory I'm using gets corrupted/overwritten. I reworked this into a test case, and would love to get some help on how to fix this. Previously I used some custom FFI calls to C to allocate aligned memory, which yields correct

Re: [Haskell-cafe] vector-simd: some code available, and some questions

2012-07-08 Thread Nicolas Trangez
On Sun, 2012-07-08 at 20:49 +1000, Reiner Pope wrote: I've not been following this thread very closely, but it seems like what you're trying to do may be related to Geoffrey Mainland's work on SIMD support in GHC. See [1] for his SIMD-enabled version of the vector library. He's also written

Re: [Haskell-cafe] vector-simd: some code available, and some questions

2012-07-08 Thread Nicolas Trangez
On Sun, 2012-07-08 at 10:27 +0200, Gábor Lehel wrote: On Sun, Jul 8, 2012 at 3:05 AM, Nicolas Trangez nico...@incubaid.com wrote: I implemented the inductive alignment calculation over One and Twice (good idea, and easy to do), but I don't get the thing about superclasses. I've been trying

[Haskell-cafe] vector-simd: some code available, and some questions

2012-07-07 Thread Nicolas Trangez
All, After my message of yesterday [1] I got down to it and implemented something along those lines. I created a playground repository containing the code at [2]. Initial benchmark results at [3]. More about the benchmark at the end of this email. First some questions and requests for help: -

Re: [Haskell-cafe] vector-simd: some code available, and some questions

2012-07-07 Thread Nicolas Trangez
On Sat, 2012-07-07 at 21:59 +0200, Gábor Lehel wrote: An alternative solution is to encode all of the alignments in unary, which is more general; if they're all going to be a power of two you can store just the logarithm: data One data Twice n -- not practical to call it Double :) class

Re: [Haskell-cafe] vector-simd: some code available, and some questions

2012-07-07 Thread Nicolas Trangez
On Sat, 2012-07-07 at 21:13 +0200, Nicolas Trangez wrote: As you can see, the zipWith Data.Vector.SIMD implementation is slightly slower than the Data.Vector.Storable based one. I didn't perform much profiling yet, but I suspect allocation and ForeignPtr creation is to blame, this seems

Re: [Haskell-cafe] vector-simd: some code available, and some questions

2012-07-07 Thread Nicolas Trangez
On Sun, 2012-07-08 at 01:40 +0200, Gábor Lehel wrote: unsafeXorSSE42 :: (Storable a, SV.AlignedToAtLeast SV.A16 o1, SV.Alignment o1, SV.AlignedToAtLeast SV.A16 o2, SV.Alignment o2, SV.AlignedToAtLeast SV.A16 o3, SV.Alignment o3) = SV.Vector o1 a - SV.Vector o2 a -

[Haskell-cafe] vector, alignment and SIMD through FFI

2012-07-06 Thread Nicolas Trangez
Hello Cafe, Recently I've been playing with the implementation of an algorithm, for which we already have highly-optimized implementations available (in plain C/C++ as well as OCaml with calls to C through FFI). The algorithm works on buffers/arrays/vectors/whatever you want to call it, which

Re: [Haskell-cafe] vector, alignment and SIMD through FFI

2012-07-06 Thread Nicolas Trangez
On Fri, 2012-07-06 at 13:43 -0700, Thomas DuBuisson wrote: On Fri, Jul 6, 2012 at 1:06 PM, Nicolas Trangez nico...@incubaid.com wrote: -- This fails: -- Ambiguous type variable `a0' in the constraint: -- (Storable a0) arising from a use of `sizeOf' Here you can either tie

[Haskell-cafe] Long-running request/response protocol server using enumerator/iterator/iterIO/pipes/conduits/...

2012-06-26 Thread Nicolas Trangez
Hello Cafe, Some time ago I tried to implement a network service using iteratee (or enumerator, can't remember), but gave up in the end. More recently I wanted to create something similar (a similar protocol), but failed again. So I'm looking for some example code or something similar (Google

Re: [Haskell-cafe] Long-running request/response protocol server using enumerator/iterator/iterIO/pipes/conduits/...

2012-06-26 Thread Nicolas Trangez
On Tue, 2012-06-26 at 21:32 +0200, Christopher Done wrote: On 26 June 2012 21:22, Nicolas Trangez nico...@incubaid.com wrote: Might sound easy (and actually it's pretty easy in most other languages I know, including an OCaml implementation), yet I fail to figure out how to get this done

Re: [Haskell-cafe] Long-running request/response protocol server using enumerator/iterator/iterIO/pipes/conduits/...

2012-06-26 Thread Nicolas Trangez
On Tue, 2012-06-26 at 22:39 +0300, Michael Snoyman wrote: I've run into those kinds of problems in the past as well. In general, interleaving of data streams can be difficult with enumerator. That's the reason I added connect-and-resume to conduit. I use the technique in warp[1], which in fact

Re: [Haskell-cafe] haskell tcp server

2012-01-18 Thread Nicolas Trangez
On Thu, 2012-01-19 at 13:12 +, Alexander V Vershilov wrote: Hello. I'm interested if there exists some library like warp but only for tcp. Or maybe some web page with skeleton for such server or with some variants, eg. concurent/single-threaded. I know that each service can have it's

Re: [Haskell-cafe] __GLASGOW_HASKELL__ for GHC 7.4

2012-01-17 Thread Nicolas Trangez
On Tue, 2012-01-17 at 15:35 +0400, Eugene Kirpichov wrote: Hi, I'm fixing a build error in a package that depends on the RTS API, which changed in 7.4, using #if __GLASGOW_HASKELL__ = 740. However, build log shows that __GLASGOW_HASKELL__ is still 704, not 740 as I'd expect. Is this a

Re: [Haskell-cafe] State Machine Composition

2011-12-21 Thread Nicolas Trangez
On Wed, 2011-12-21 at 18:34 +, Daniel Waterworth wrote: I made this simple state machine combinator library today. I think it works as a simple example of a good use for GADTs. https://gist.github.com/1507107 Any way to do something along the lines of type StateChange a = SC a a