News aggregator

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

problem installing postgreSQL-libpq on Windows

haskell-cafe - Thu, 06/16/2016 - 8:19am
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\libpq.dll" > libpq.def From the msys prompt: dlltool -d libpq.def -l libpq.a The file libpq.a is created. I copied the file to d:\program files\postgreSQL\9.3\bin\ and then from de cmd prompt: cabal install postgreSQL-libpq --extra-include-dirs="d:\program files\postgreSQL\9.3\include" --extra-lib-dirs="d:\program files\postgreSQl\9.3\bin" I get: Resolving dependencies... Configuring postgresql-libpq-0.9.1.1... Failed to install postgresql-libpq-0.9.1.1 Build log ( C:\Users\kees\AppData\Roaming\cabal\logs\postgresql-libpq-0.9.1.1.log ): [1 of 1] Compiling Main ( D:\Temp\cabal-tmp-6140\postgresql-libpq-0.9.1.1\dist\setup\setup.hs, D:\Temp\cabal-tmp-6140\postgresql-libpq-0.9.1.1\dist\setup\Main.o ) Linking D:\Temp\cabal-tmp-6140\postgresql-libpq-0.9.1.1\dist\setup\setup.ex
Categories: Offsite Discussion

ICPE 2017 - 1st Call for Papers

General haskell list - Wed, 06/15/2016 - 10:42pm
ICPE 2017 8th ACM/SPEC International Conference on Performance Engineering Sponsored by ACM SIGMETRICS, SIGSOFT, and SPEC RG L'Aquila, Italy April 22-26, 2017 https://icpe2017.spec.org/ ------------------------------------------------------------------------ IMPORTANT DATES Research and Industrial / Experience Abstracts: Sep 23, 2016 Research and Industrial / Experience Papers: Sep 30, 2016 Research and Industrial / Experience Paper Notification: Nov 18, 2016 Work-in-Progress/Vision Papers: Nov 25, 2016 Workshop Proposals: Nov 05, 2016 Workshop Proposal Notification: Nov 19, 2016 Dates for tutorials, posters and demos will be announced. ------------------------------------------------------------------------ SCOPE AND TOPICS The goal of the International Conference on Performance Engineering (ICPE) is to integrate theory an
Categories: Incoming News

This non-exhaustive pattern match seems exhaustive

haskell-cafe - Wed, 06/15/2016 - 9:33pm
I'm emulating a "closed typeclass" using a closed type family: * {-# LANGUAGE ExistentialQuantification #-}* * {-# LANGUAGE GADTs #-}* * {-# LANGUAGE LambdaCase #-}* * {-# LANGUAGE TypeFamilies #-}* * import GHC.Exts (Constraint)* * -- This is like* * --* * -- class Thing a -- instance Thing Int --* * type family Thing a :: Constraint where* * Thing Int = ()* * data Foo = forall a. Thing a => Foo (Bar a)* * data Bar a where* * Bar1 :: Bar Int* * Bar2 :: Bar Bool* * inspectFoo :: Foo -> ()* * inspectFoo = \case* * Foo Bar1 -> ()* * Foo Bar2 -> () -- This is required to suppress a warning* Here, it's not possible to create a Foo using "Foo Bar2", because there is no "Thing Bool" constraint in scope. Yet, when picking apart a Foo, I must still pattern match on this impossible data. Is there some smarter way to write this code? I thought of using `constraints`, and adding a catch
Categories: Offsite Discussion

SPLASH'16: 2nd Combined Call for Contributions toCollocated Events

General haskell list - Wed, 06/15/2016 - 9:12pm
################################################# ACM Conference on Systems, Programming, Languages, and Applications: Software for Humanity (SPLASH'16) ################################################# Amsterdam, The Netherlands Sun 30th October - Fri 4th November , 2016 http://2016.splashcon.org https://twitter.com/splashcon https://www.facebook.com/SPLASHCon/ Sponsored by ACM SIGPLAN Combined Call for Contributions to SPLASH tracks, collocated conferences, symposia and workshops: - SPLASH-I, SPLASH-E, Doctoral Symposium, Student Research Competition, Programming Languages Mentoring Workshop, Posters - Generative Programming: Concepts & Experiences (GPCE) - Software Language Engineering (SLE) - Scala Symposium - Workshops: AGERE, DSLDI, DSM, FOSD, ITSLE, LWC< at >SLE, META, MOBILE!, NOOL, PLATEAU, Parsing< at >SLE, REBLS, RUMPLE, SA-MDE, SEPS, VMIL, WODA The ACM SIGPLAN conference on Systems, Programming, Languages and Applications: Software for Humanity (SPLASH) embraces all aspects of software construction,
Categories: Incoming News

How to spot Monads, Applicatives ...

haskell-cafe - Wed, 06/15/2016 - 4:54pm
Hello all, I am at a stage, where I can use some of the Monads and Applicatives which are out there. But I hardly ever wrote my own instances. I am curious to learn about the thought processes which lead to the insight "hey that can be written nicely as an Applicative Functor" I suppose you can write everything without these type classes. Is it a promising approach to try without and then spot an element of repetition and factoring out that naturally leads to one of these typeclasses? Paticularly I am having difficulties with the *->* instances. E.g. why is the state "s" in the state monad the fixed type and the "a" the type parameter? When I am writing state code without the State monad the two look like equal candidates. Why not have "State a" monad, which threads an a-typed value and spits out states? While we're at it: would someone be so kind and explain what exactly is meant by an "effect"? I know that in haskell this is not the same as a "side effect" as there are no side-effects in haskell.
Categories: Offsite Discussion

ANN: eccrypto, aka Hecc, hF2

haskell-cafe - Wed, 06/15/2016 - 8:35am
Dear Haskell Community! It was a long~ish time ago I released hecc[1], which had an unfortunate but funny (to me) name, later together with hF2[2]. Since I have neither released hyperelliptic curve crypto support, nor my pairing based crypto, a generalising change in names would be in order. Today I am releasing eccrypto[3], which contains the code of both (to allow easier refactoring of new ideas) and something new: A pure Haskell, timing-attack resistant Ed25519[4] implementation! ...well, a very rough one at least. The code is not "done", gives wrong results, is _very_ slow, but it might serve as reading material as well as a primer what I plan to do in the future. I do not plan to add embedded C or assembler code, but plan to make the code comparatively fast to some common implementations as well as timing attack resistant (see: [5]), even if it will never be as fast as the best code used in contemporary benchmarks. Sadly, due to health issues, I am not able to work on said code and have not been for
Categories: Offsite Discussion