News aggregator

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

Magnus Therning: Free, take 2

Planet Haskell - Fri, 06/17/2016 - 6:00pm

The other day I read a blog post on monads and stuff after which I felt rather silly about my earlier posts on Free.

I think this is probably the post I should have written instead :)

I’ll use three pieces of code, each one builds on the one before:

  • Free1.hs - Uses a free monad for a single algebra/API (full code here).
  • Free2.hs - Uses a free monad for a two algebras/APIs, where one decorates the other (full code here).
  • Free3.hs - Uses a free monad for a three algebras/APIs, where two are used in the program and the remaing one decorates the other two (full code here).
The first - one algebra

I’m re-using the algebras from my previous posts, but I believe it makes it easier to follow along if the amount of jumping between posts is minimized so here is the first one once again:

data SimpleFileF a = LoadFile FilePath (String -> a) | SaveFile FilePath String a deriving(Functor) type SimpleFileAPI = Free SimpleFileF loadFile :: FilePath -> SimpleFileAPI String loadFile fp = liftF $ LoadFile fp id saveFile :: FilePath -> String -> SimpleFileAPI () saveFile fp d = liftF $ SaveFile fp d ()

It’s a ridiculously small one, but I believe it’s good enough to work with. In the previous posts I implemented the Functor instances manually. I couldn’t be bothered this time around; I think I pretty much know how to do that for this kind of types now.

Having a type for the algebra, SimpleFileAPI, is convenient already now, even more so in the other examples.

The two convenience functions on the end makes it straight forward to write functions using the algebra:

withSimpleFile :: (String -> String) -> FilePath -> SimpleFileAPI () withSimpleFile f fp = do d <- loadFile fp let result = f d saveFile (fp ++ "_new") result

This is simple, straight forward monadic code. Easy to read and work with. Of course it doesn’t actually do anything at all yet. For that I need need an interpreter, something that translates (reduces) the algebra, the API, the commands, call them what you will, into the (side-)effects I want. For Free that is foldFree together with a suitable function f :: SimpleFileF a -> IO a.

I want LoadFile to translate to a file being read and SaveFile to some data being saved to a file. That makes it pretty obvious how that f needs to be written:

runSimpleFile :: SimpleFileAPI a -> IO a runSimpleFile = foldFree f where f (LoadFile fp f') = f' <$> readFile fp f (SaveFile fp d r) = writeFile fp d >> return r

At this point it might be good to explain the constructors of SimpleFileF a bit more. At first I thought they looked a bit funny. I mean, why does SaveFile have an a at all since it obviously always should result in ()? And what’s up with that function in Loadfile?

It did become a little clearer to me after some thought and having a look at Free:

data Free f a = Pure a | Free (f (Free f a))

I personally find the latter constructor a bit mind-bending. I can handle recursive functions fairly well, but recursive types have a tendency to confuse me. From what I understand one can think of Free as similar to a list. Pure ends the list (Nil) and Free one instance of f to the rest of the list (Cons). Since Free f a is a monad one can think of a as the result of the command.

If I were to write saveFile explicitly it’d look like this

saveFile fp d = Free (SaveFile fp d (Pure ()))

and for loadFile:

loadFile fp = Free (LoadFile fp (\ s -> Pure s))

But let’s get back to the type and why ‘a’ occurs like it does in the two constructors. As Gabriel G shows in his post Why free monads matter a constructor without a would result in termination. In other words, if SaveFile didn’t hold an a I’d not be able to write, in a natural way, a function that saves two files.

Another limiting factor is that foldFree of the Free implementation I’m using has the type Monad m => (forall x. f x -> m x) -> Free f a -> m a. This sets a requirement on what the function translating from my API into effects may look like, i.e. what f in runSimpleFile may look like. If SaveFile had no a to return what would f (SaveFile {}) return, how could it ever satisfy the required type?

The reason for LoadFile having a function String -> a is simply that there is no data yet, but I still want to be able to manipulate it. Using a function and function composition is the ticket then.

I think that’s all there is to say about to the first piece of code. To run it take a look at the comment at the end of the file and then play with it. If you want to turn all characters of a file foo into upper case you can use

runSimpleFile $ withSimpleFile (map toUpper) "foo" The second - two algebras, one decorating the other

The second piece of code almost only adds to the first one. There is one exception though, the function runSimpleFile is removed. Instead I’ve taken the transformation function, which used to be called f and was internal to runSimpleFile and moved it out. It’s called stepSimpleFile:

stepSimpleFile :: SimpleFileF a -> IO a stepSimpleFile (LoadFile fp f') = f' <$> readFile fp stepSimpleFile (SaveFile fp d r) = writeFile fp d >> return r

The logging API, LogAPI, follows the same pattern as SimpleFileAPI and I’m counting on the description above being clear enough to not have to repeat myself. For completeness I include the code:

data LogF a = Log String a deriving(Functor) type LogAPI = Free LogF stepLog :: LogF a -> IO a stepLog (Log s r) = putStrLn s >> return r

I intend the LogAPI to be used as embellishments on the SimpleFileAPI, in other words I somehow have to turn an operation of SimpleFileAPI into an operation of LogAPI, i.e. I need a transformation. I called it logSimpleFileT and let it turn operations in SimpleFileF (i.e. not exactly SimpleFileAPI) into LogAPI (if you are wondering about my choice of type I hope it’ll become clear below, just trust me for now that this is a good choice):

logSimpleFileT :: SimpleFileF a -> LogAPI () logSimpleFileT (LoadFile fp _) = liftF $ Log ("** load file " ++ fp) () logSimpleFileT (SaveFile fp _ _) = liftF $ Log ("** save file " ++ fp) ()

So far everything is hopefully very straight forward and unsurprising. Now I need to combine the two APIs, I need to add them, in other words, I need a sum type:

data S a1 a2 t = A1 (a1 t) | A2 (a2 t) deriving(Functor) type SumAPI = Free (S LogF SimpleFileF)

The next question is how to turn my two original APIs, SimpleFileAPI and LogAPI, into SumAPI. Luckily that’s already solved by the function hoistFree:

hoistFree :: Functor g => (forall a. f a -> g a) -> Free f b -> Free g b

With this and logSimpleFileT from above I can use foldFree to decorate each operation with a logging operation like this:

logSimpleFile :: SimpleFileAPI a -> SumAPI a logSimpleFile = foldFree f where f op = hoistFree A1 (logSimpleFileT op) *> hoistFree A2 (liftF op)

This is where the type of logSimpleFileT hopefully makes sense!

Just as in the first section of this post, I need an interpreter for my API (SumAPI this time). Once again it’s written using foldFree, but this time I provide the interpreters for the sub-algegras (what I’ve chosen to call step functions):

runSum :: Monad m => (forall a. LogF a -> m a) -> (forall a. SimpleFileF a -> m a) -> SumAPI b -> m b runSum f1 f2 = foldFree f where f (A1 op) = f1 op f (A2 op) = f2 op

The file has a comment at the end for how to run it. The same example as in the previous section, but now with logging, looks like this

runSum stepLog stepSimpleFile $ logSimpleFile $ withSimpleFile (map toUpper) "foo" The third - three algebras, one decorating the other two

To combine three algebras I simply take what’s in the previous section and extend it, i.e. a sum type with three constructors:

data S a1 a2 a3 t = A1 (a1 t) | A2 (a2 t) | A3 (a3 t) deriving(Functor) type SumAPI = Free (S LogF SimpleFileF StdIoF) runSum :: Monad m => (forall a. LogF a -> m a) -> (forall a. SimpleFileF a -> m a) -> (forall a. StdIoF a -> m a) -> SumAPI b -> m b runSum f1 f2 f3 = foldFree f where f (A1 op) = f1 op f (A2 op) = f2 op f (A3 op) = f3 op

With this I’ve already revealed that my three APIs are the two from previous sections, LogAPI (for decorating the other APIs), SimpleFileAPI and a new one, StdIoAPI.

I want to combine them in such a wat that I can write functions using both APIs at the same time. Then I modify withSimpleFile into

withSimpleFile :: (String -> String) -> FilePath -> SumAPI () withSimpleFile f fp = do d <- loadFile fp let result = f d saveFile (fp ++ "_new") result

and I can add another function that uses it with StdIoAPI:

prog :: FilePath -> SumAPI () prog fn = do stdioPut "About to start" withSimpleFile (map toUpper) fn stdioPut "Done!"

The way to allow the APIs to be combined this way is to bake in S already in the convenience functions. This means the code for SimpleFileAPI has to change slightly (note the use of A2 in loadFile and saveFile):

data SimpleFileF a = LoadFile FilePath (String -> a) | SaveFile FilePath String a deriving(Functor) loadFile :: FilePath -> SumAPI String loadFile fp = liftF $ A2 $ LoadFile fp id saveFile :: FilePath -> String -> SumAPI () saveFile fp d = liftF $ A2 $ SaveFile fp d () stepSimpleFile :: SimpleFileF a -> IO a stepSimpleFile (LoadFile fp f') = f' <$> readFile fp stepSimpleFile (SaveFile fp d r) = writeFile fp d >> return r

The new API, StdIoAPI, has only one operation:

data StdIoF a = PutStrLn String a deriving(Functor) stdioPut :: String -> SumAPI () stdioPut s = liftF $ A3 $ PutStrLn s () stepStdIo :: StdIoF b -> IO b stepStdIo (PutStrLn s a) = putStrLn s >> return a

The logging API, LogAPI, looks exactly the same but I now need two transformation functions, one for SimpleFileAPI and one for StdIoAPI.

data LogF a = Log String a deriving(Functor) type LogAPI = Free LogF stepLog :: LogF a -> IO a stepLog (Log s r) = putStrLn s >> return r logSimpleFileT :: SimpleFileF a -> LogAPI () logSimpleFileT (LoadFile fp _) = liftF $ Log ("** load file " ++ fp) () logSimpleFileT (SaveFile fp _ _) = liftF $ Log ("** save file " ++ fp) () logStdIoT :: StdIoF a -> LogAPI () logStdIoT (PutStrLn s _) = liftF $ Log ("** on stdio " ++ s) ()

The new version of logT needs to operate on S in order to decorate both APIs.

logT :: SumAPI a -> SumAPI a logT = foldFree f where f (A2 op) = hoistFree A1 (logSimpleFileT op) *> hoistFree A2 (liftF op) f (A3 op) = hoistFree A1 (logStdIoT op) *> hoistFree A3 (liftF op) f a@(A1 _) = liftF a

This file also has comments on how to run it at the end. This time there are two examples, one on how to run it without logging

runSum undefined stepSimpleFile stepStdIo $ prog "foo"

and one with logging

runSum stepLog stepSimpleFile stepStdIo (logT $ prog "foo")
Categories: Offsite Blogs

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

ANN: eccrypto, aka Hecc, hF2

libraries list - Wed, 06/15/2016 - 8:13am
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

Help with Data.Conduit.List.mapAccum

haskell-cafe - Wed, 06/15/2016 - 6:53am
Hello, I'm trying to use Data.Conduit, but I get stuck with mapAccum as how to get and retrieve the result. If I use it, I get a simple conduit like : testC :: ConduitM () Int IO Int testC = Src =$= cdt where src = CL.sourceList [1..10] cdt = CL.mapAccum (\x s ->(x+s, x) 0 I can get the output with testC $$ CL.consume but how do I retrieve the accumulated sum ? Bruno _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion