News aggregator

Resumable applicative parsing from tail end?

haskell-cafe - Mon, 06/20/2016 - 11:42am
Hello all, in my attempt to write a simulation program, I am facing the following problem: as the simulation progresses, I collect "primary" log entries, each one associated with a timestamp. These entries carry the information I am interested in (and not so much the final state). Currently I am using a simple list to collect log entries. Since (:) is so much easier than (++) I prepend new entries to the head of the list. So my log runs backwards in time with the oldest entries at the tail end. Because the log-entries are typically too fine-grained to be useful, I want to aggregate several of them into a single log entry in a secondary log. I want to do this "as I go" and discard primary log entries which are already aggregated. Thus I can keep the primary log reasonably small. I thought that aggregation is just a special case of parsing. And indeed, I could write an applicative parser PrimaryLog -> (PrimaryLog, SecondaryLog) which does the trick, except I had to reverse the ordering of the primary lo
Categories: Offsite Discussion

How to avoid expensive and unnecessary typeconversions?

haskell-cafe - Mon, 06/20/2016 - 12:01am
Suppose you have a class ListLike (which you do have, actually) and it has methods for operations on types that are like lists, and in particular it has a method fromListLike which converts any ListLike value to any other: fromListLike :: ListLike full' item => full' -> full the default implementation of this is simply fromListLike = fromList . toList but this means that if you happen to apply fromListLike to a value which is already the desired type, two unnecessary and possibly expensive conversions take place. My question is, how can one write code that implements fromListLike in such a way that when the two type parameters are the same type it just uses fromListLike = id I've thought about using a class Convert a b class and writing an instance for every pair of ListLike instances. I haven't convinced myself this would work, and if it does it means that adding a new instance involves writing a bunch of Convert instances. Maybe one could somehow have a default implementation (fromList
Categories: Offsite Discussion

Proposal: add ReadPrec-based functions to Read1/Read2

libraries list - Sun, 06/19/2016 - 9:40pm
GHC 8.0 added the Data.Functor.Classes module [1] to base, and with it the Read1 and Read2 typeclasses. The current definition of Read1 is this: class Read1 f where liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a) liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [f a] There's a pretty big problem with this definition: it uses ReadS (a synonym for String -> [(a, String)]). This sort of parser is very slow (the docs even admit as such [2]), and moreover, the actual Read typeclass on which Read1 is based tries to avoid using it whenever possible. The Read typeclass has this definition currently: class Read a where readsPrec :: Int -> ReadS a readList :: ReadS [a] readPrec :: ReadPrec a readListPrec :: ReadPrec [a] Where ReadPrec is a much more efficient parser datatype. When deriving Read instances, GHC defines them in terms of readPrec, and gives the other methods default definitions that leverage readPrec. For t
Categories: Offsite Discussion

Simon's email classified as spam

glasgow-user - Sun, 06/19/2016 - 8:08pm
Dear GHC devs/users This is another test to see if email from me, relayed via Haskell.org, ends up in your spam folder. Gershom thinks he’s fixed it (below). Can I trespass on your patience once more? Just let me know if this email ends up in your inbox or spam. Can you cc John and Gershom (but perhaps not everyone else)? Thanks Simon | From: Gershom B [mailto:gershomb< at >gmail.com] | Sent: 18 June 2016 18:53 | To: Simon Peyton Jones <simonpj< at >microsoft.com>; John Wiegley | <johnw< at >newartisans.com> | Cc: Michael Burge <michaelburge< at >pobox.com> | Subject: Re: FW: CMM-to-SAM: Register allocation weirdness | | Simon — I just found two possible sources of the problem (first: the top | level config didn’t take hold due to other errors when updating — fixed that, | and second, it might be possible the top level config isn’t retroactively | applied to all lists — so i added the config to the relevant lists directly). | | I think if you try one more time it might work (fingers crossed). ____
Categories: Offsite Discussion

Problem binding GEGL library

haskell-cafe - Sun, 06/19/2016 - 2:48pm
Hello fellow haskellers, I am currently working on Haskell bindings to the GEGL [0] library. Since it's my first time working with the FFI and the whole idea of binding a library into Haskell, I have now run into a problem I can't resolve myself. The GEGL headers expose a function "gegl_buffer_iterator_new" which returns an iterator over a selected area in a buffer. This iterator contains a float pointer with pixel data. My problem is to make the iterator and the data it contains accessible to Haskell and to iterate over it. Can someone of you please help me with this problem? One of my initial thoughts was to wrap it into a monad, but I am totally inexperienced with that. My project can be found on my Github profile [1]. Many thanks in advance, nek0 links: [0]: http://www.gegl.org/ [1]: https://github.com/nek0/gegl _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-c
Categories: Offsite Discussion

Compose :: Conference, Melbourne, 2016,Call for Presentations!

haskell-cafe - Sun, 06/19/2016 - 3:10am
(Web version: http://www.composeconference.org/2016-melbourne/cfp/) # Call for Presentations Compose Melbourne - http://www.composeconference.org/ - is pleased to announce its call for presentations. Compose Melbourne is a new functional programming conference focused on developing the community and bringing typed functional programming to a wider audience. It is a 2-day event being held in Melbourne, Australia on the 29th and 30th of August 2016. The first day features a single track of presentations followed by a second day of workshops and an unconference. It is the new sister-conference of the NY based Compose Conference. Submit your presentation proposal here: https://easychair.org/conferences/?conf=cmc2016 # Important Dates - CFP Launch Party - 19th May - CFP Opens - 19th May - CFP Closes - June 30th - Notify Presenters - July 15th - Conference Day 1: Presentations - Monday, 29-Aug-2016 - Conference Day 2: Unconference - Tuesday, 30-Aug-2016 # Talk and Workshop Submission ## Day 1 - Presentat
Categories: Offsite Discussion

My responses to challenge problems in BartoszMilewski's "Category Theory for Programmers", thru Ch. 10.

haskell-cafe - Sun, 06/19/2016 - 12:03am
Hi all, I just finished chapter 10 in Bartosz Milewski’s “Category Theory for Programmers”, and thought I’d share my responses to his challenge problems: https://htmlpreview.github.io/?https://github.com/capn-freako/Haskell_Misc/blob/master/Bartosz_Milewski_Functors.html I’d love to hear anyone’s feedback. Cheers, -db _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

ST Vector / STRef -- Performances and allocation

haskell-cafe - Sat, 06/18/2016 - 9:37pm
Hello. I read a reddit post [0] which ends in a debate about haskell performances. Someone gives a C implementation which runs in 15ms on some dataset. I wanted to learn about mutable vector and ST and got something in haskell which runs in 50ms. Code is here [1]. [0] https://www.reddit.com/r/haskell/comments/4ojsn0/counting_inversions_haskell/ [1] https://github.com/guibou/inversionsCount/blob/syntax/inversions.hs When I'm profiling the code, I'm surprised to see more than 50% of the %alloc in function which, from my point of view, must not allocate. For example, this function : inc :: forall s. STRef s Int -> ST s () inc v = modifySTRef' v (+1) Is responsible for 10% of the allocation in this program. I was hoping that the "unboxing magic" of GHC may have replaced my Int somewhere by an unboxed one, but I guess the allocation means that the STRef is somehow pointing to a heap allocated Int. Do you know a way to remove theses allocations? As a second question, if you see any other way to improve thi
Categories: Offsite Discussion

bit sets in IntSet vs. Integer

libraries list - Sat, 06/18/2016 - 2:59pm
In my set-cover package I make extensive use of bit vectors. I tested both IntSet and Integer for this purpose. In GHC-7.4.2 Integer was visibly faster than IntSet, but in GHC-7.8.4 and later, IntSet clearly wins over Integer. I guess this can be attributed to IntSet using BitMaps at the leaves since containers-0.5. However, on a 64-bit machine a BitMap is a Word64. I wondered whether we could get further speedup by using a vector type. E.g. AVX processors could perform bit manipulations on 256 bit words. Do the bit operations on Integer make use of vector instructions? _______________________________________________ Libraries mailing list Libraries< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Categories: Offsite Discussion

Monad Stack - State + Rand?

haskell-cafe - Sat, 06/18/2016 - 5:22am
Hi. I'm working through "Haskell Design Patterns" and got inspired to try to create my first monad stack. What I really wanted though (not shown in the book) was to combine State and Rand. I daresay I got something to compile: walk :: RandomGen g => StateT (Float, Float) (Rand g) (Float, Float) walk = do (x, y) <- get put (x + 1, y + 1) get >>= return However, the moment I try to insert a getRandomR or something in it, I get an error Could not deduce (MonadRandom (StateT (Float, Float) (Rand g))) arising from a use of `getRandomR' <...snip...> add an instance declaration for (MonadRandom (StateT (Float, Float) (Rand g))) I see there are instances MonadRandom m => MonadRandom (StateT s m) RandomGen g => MonadRandom (Rand g) in Control.Monad.Random.Class, so I am not quite sure what is expected of me.
Categories: Offsite Discussion

Macros For Cabal Version

haskell-cafe - Sat, 06/18/2016 - 12:14am
Hi all, I have a non-trivial build script that I'm trying to make compatible with Cabal 1.22 and Cabal 1.24. So far the only macro I can find that helps me determine which version I'm using is __GLASGOW_HASKELL__. Is there a better one? Thanks! -deech _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

INLINABLE and SPECIALIZE, GHC 8.0.1

haskell-cafe - Fri, 06/17/2016 - 12:01pm
I'm trying to write a mutable hash table library that would work both in the IO and ST monads, so I'm using the PrimMonad typeclass [see JmoyHash.hs in the attached archive]. For efficiency, I would like the functions to be specialized to the concrete monad at the call site. According to Section 9.31.9.2 of the GHC User's Guide <https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#specialize-for-imported-functions> The optimiser *also* considers each *imported* INLINABLE overloaded function, and specialises it for the different types at which it is called in M. So I marked all the functions in my library as INLINABLE. Yet adding a SPECIALIZE pragma in Main.hs (currently commented out) for an imported function improves runtime performance by 3x, which should not be happening since, if I understand the manual right, the function should have been specialized anyway since it is marked INLINABLE. I am writing to this list rather than filing a bug since I'm not sure if I'm reading
Categories: Offsite Discussion

WFLP 2016 - Deadline Extension

General haskell list - Fri, 06/17/2016 - 9:06am
24th International Workshop on Functional and (Constraint) Logic Programming (WFLP 2016) https://wflp2016.github.io/ September 13-14, part of the Leipzig Week of Declarative Programming (L-DEC 2016) The deadlines have been extended by a week, but are nearing soon. We will have proceedings published by EPTCS (http://www.eptcs.org/). Both full technical papers and less formal work-in-progress reports are welcome, as are system descriptions. More details below and on the web page. *********************************************************** Deadlines: * abstract submission: June 22, 2016 (extended) * paper submission: June 29, 2016 (extended) * notification: July 15, 2016 * camera-ready (workshop) version due: August 10, 2016 Submissions can be directly accepted for publication in the formal EPTCS proceedings, or accepted for presentation at the workshop and invited to another round of reviewing after revision. *********************************************************** The international workshops on
Categories: Incoming News

Instances for (->) a (b :: * -> *)?

haskell-cafe - Fri, 06/17/2016 - 6:33am
If one wants to declare instances for a type schema `a -> _`, one writes something like this: instance Context => Class parameters ... ((->) a) where { ... } But what if you want to declare instances for a type schema `a -> b _`, that is, where the slot to be filled is not just the result of (->) a, but rather the composition of that together with another type operation b :: * -> *? I'd like to write something like this: instance Context => Class parameters ... ((->) a (b :: *->*)) where { ...} or: instance Context => Class parameters ... ((->) a (b *)) where { ...} but these don't work. Is it possible to do this? Concretely, here's what I'm trying to achieve. I wrote a typeclass for MonadReaders that are embedded inside (one level) of other MonadReaders, like this: {-# LANGUAGE FunctionalDependencies FlexibleInstances UndecidableInstances #-} class MonadReader w m => DeepMonadReader w r m | m -> r where { deepask :: m r ; deepask = deepreader id ; de
Categories: Offsite Discussion

Trying to test natural transformations, in Haskell.

haskell-cafe - Fri, 06/17/2016 - 4:40am
Got it: {-# LANGUAGE Rank2Types AllowAmbiguousTypes FlexibleContexts #-} type NatTran f f' a = (Functor f, Functor f') => f a -> f' a to_assert :: (Functor f, Functor f', Eq (f' b)) => (a -> b) -> NatTran f f' a -> NatTran f f' b -> f a -> Bool to_assert g h h' f = (fmap g . h) f == (h' . fmap g) f maybe_to_list :: NatTran Maybe [] a maybe_to_list Nothing = [] maybe_to_list (Just x) = [x] test_func :: Num a => a -> (a, a) test_func x = (x, x + 1) success = all (to_assert test_func maybe_to_list maybe_to_list) [Nothing, Just 1] main :: IO () main = do if success then print "Success!" else print "Failure." main Running this code produces: "Success!" ================================================= Hi all, In doing the challenge problems at the end of chapter 10 (Natural Transformations) in Bartosz Milewski’s “Category Theory for Programmers”, I’m trying to write a generic naturality checker: {-# LANGUAGE Rank2Types AllowAmbiguousTypes #-}
Categories: Offsite Discussion

Trying to test natural transformations, in Haskell.

haskell-cafe - Fri, 06/17/2016 - 4:02am
Hi all, In doing the challenge problems at the end of chapter 10 (Natural Transformations) in Bartosz Milewski’s “Category Theory for Programmers”, I’m trying to write a generic naturality checker: {-# LANGUAGE Rank2Types AllowAmbiguousTypes #-} type NatTran a = (Functor f, Functor f') => f a -> f' a to_assert :: (Functor f, Eq b) => (a -> b) -> NatTran a -> NatTran b -> f a -> Bool to_assert g h h' f = (fmap g . h) f == (h' . fmap g) f which is later made specific to a particular natural transformation: maybe_to_list :: Maybe a -> [a] maybe_to_list Nothing = [] maybe_to_list (Just x) = [x] test_func :: Num a => a -> (a, a) test_func x = (x, x + 1) assertions = map (to_assert test_func maybe_to_list) [Nothing, Just 1] but I’m getting this from ghc: Could not deduce (Functor f0) arising from a use of ‘fmap’ from the context (Functor f, Eq b) bound by the type signature for interactive:IHaskell465.to_assert :: (Functor f, Eq b) => (a -> b) -> interactive:IHaskell465.Na
Categories: Offsite Discussion

($) and ApplicativeDo

haskell-cafe - Thu, 06/16/2016 - 5:08pm
foo :: Applicative f => f String foo = do x <- pure "this works" pure x ... but replace "pure x" with "pure $ x" and it doesn't typecheck: a monad instance is required! Tom
Categories: Offsite Discussion

partial solved problem installing postgreSQL-libpqon Windows?

haskell-cafe - Thu, 06/16/2016 - 12:49pm
Hi Kees, Would It be possible for you to try with GHC 7.10.3 or 8.0.1? A bunch of things have changed with the linker in these two versions which should make linking against packages easier. <command line>: can't load .so/.DLL for: ghc.exe: d:/PROGRA~2/POSTGR~1/9.3/lib\libpq: %1 is not a valid Win32 This seems to be coming from the runtime linker, if indeed d:/PROGRA~2/POSTGR~1/9.3/lib\libpq.dll can be found then either it's the wrong bitness/image type or libpq.dll has dependencies on other dlls. 7.10.1 is not able to load these then as the search path won't be correct. To test this you can add d:/PROGRA~2/POSTGR~1/9.3/lib\ to your path and try loading it again. If that doesn't work and you want to know what's really going on, you can enable loader snaps in gflags for GHC.exe and GHCi.exe (or runHaskell, what ever it is you're using) and attach a debugger like gdb or windbg. https://msdn.microsoft.com/en-us/library/windows/hardware/ff556886(v=vs.85).aspx You'll then be able to see the OS's trace
Categories: Offsite Discussion

partial solved problem installing postgreSQL-libpqon Windows?

haskell-cafe - Thu, 06/16/2016 - 10:47am
Maybe I've found a part of the solution. I changed in postgresql-libpq.cabal Extra-Libraries: from pq to libpq. Then runHaskell xx configure -ghc, runHaskell xx build and then runHaskell xx install. No errors.. I'am happy. But. if I try to install postgresql-simple or hasql I get this error : .. <command line>: can't load .so/.DLL for: d:/PROGRA~2/POSTGR~1/9.3/lib\libpq.dll (addDLL: could not load DLL) ghc.exe: d:/PROGRA~2/POSTGR~1/9.3/lib\libpq: %1 is not a valid Win32 application. ... dir d:\PROGRA~2\POSTGR~1\9.3\lib\libpq.dll finds the dll, but d:/PROGRA~2/POSTGR~1/9.3/lib/libpq.dll gives: 'Parameter format not correct'. These mangled filenames come from pg_config.exe. Is this a filename mangling problem? Any idea what is going on? Kees --------------------------- I want to install postgreSQL-libpq on Windows 7 64 bits with ghc version 7.10.1 and cabal version 1.22.4.0 This is what I did: Installed mingw From the msys prompt: pexports "d:\program files\postgreSQL\9.3\bin\libp
Categories: Offsite Discussion

base version numbers

haskell-cafe - Thu, 06/16/2016 - 8:58am
Since each version of GHC depends precisely on one version of base, would it not be more clear to name them after their version of GHC, rather than 4.x.y.z? Could this be done? Tom
Categories: Offsite Discussion