We can simplify this function: product ys = foldl (\ acc x -> x*acc ) 1 ys into this one: product' = foldl1 (*)
But supposing we just had product = foldl1 (*), could we know how to expand it, or could it be expanded to any number of legitimate functions?submitted by tmtwd
[link] [4 comments]
In category theory, a functor is a transformation on a category which preserves composition. Because categories have both objects and morphisms, each functor has to be defined based on his action on both.
Haskell functors only have fmap, which represents the action of the functor on morphisms. Why no lift?submitted by PM_ME_UR_OBSIDIAN
[link] [15 comments]
In this package: http://hackage.haskell.org/package/wiring
There is support for transforming instances of ReaderT/WriterT/RWST so that it's easier to build components using those types and pull them together to build larger components and services within an application.
For example with a couple of methods like this:userLookup :: Int -> ReaderT (Resource1, Database1) IO User ordersLookup :: Int -> ReaderT (Database2, Resource1) IO [String]
It's possible to pull them together like this:composedLookup :: Int -> ReaderT (Resource1, Database1, Database2) IO String composedLookup userId = do user <- wire $ userLookup userId orders <- wire $ ordersLookup userId return $ describeOrders user orders submitted by seantparsons
[link] [6 comments]
Program slicing is a program transformation technique that slices away needless parts of a program, by trying to only keep around the parts of the program that are relevant relative to a slicing criterion. The background of the technique is from imperative programming, where the standard example is a procedure that calculates both the sum of the numbers 1 to n and the factorial of n and prints these numbers. Then you can slice the program on two criterion: printing the sum, or the factorial. The program slicer will eliminate all statements that are useless for each respective purpose, like deleting all statements that have to do with the factorial if all you are after is the sum.
In FP, it seems that the equivalent to slicing away statements is to slice away sub-expressions. As far as I know, one of the upsides of lazy evaluation is that the code becomes more modular in a composability-sense - like the fact that minimum = head . sort has a complexity of just O(n). So this advantage seems similar to program slicing - effectively optimize a program by just opting out of doing certain steps. Of course even if they achieve a similar goal, they are very different - one is a program transformation technique, the other is an evaluation strategy. But can, for example, program slicing be applied to a strict language in order to get some of the same benefits with regards to modularity and composability of code that you would get in a non-strict language?
I have tried to search around for this, but I haven't found anyone who bring up these two concepts together. Which makes me suspect that I have misinterpreted the utility of program slicing.submitted by krishill
[link] [2 comments]
We are currently working on a package which provides an Apache Kafka implementation in Haskell. This includes: types, parsing and serialising for the given APIs. On top of this, a client library is provided which can be used to build consumer and producer clients.
As for now, we have Produce and Fetch APIs working. There is also a producer and consumer console-client they already use the protocol package and are fully compatible with Apache Kafka! Consumer: https://github.com/hmb-ba/console-consumer Producer: https://github.com/hmb-ba/console-producer
But why here on reddit? Well, as a matter of fact, we are haskell beginners and since this is part of our bachelors thesis and meanwhile also our favourite project, we hope to find some feedback and best case some code reviews of more advanced haskell devs :) But any thoughts are (be it code or project related or none at all) are welcome!submitted by mjnet
[link] [4 comments]
Has anybody tried developing for Android in Haskell? How was it? Which library was it? How about the performance and the size of the apk?submitted by gilded_honour
[link] [6 comments]
We've just got some chickens and my girlfriend asked me if I could find a solution to open and close the door of the chicken house automatically (when the sun rise/set). That seems the perfect opportunity for a little Arduino/Raspberry Pi project.
I don't know anything about them, but from what I've seen, the Arduino seems more adapted for that kind of project. However, I would prefer to program it in Haskell (to double the fun) but from what I've read it's not possible (yet) to compile Haskell to Arduino where it seems possible with Raspberry Pi.
Has anybody experience with using Haskell with them ?submitted by maxigit
[link] [25 comments]
After reading https://awelonblue.wordpress.com/2012/10/21/local-state-is-poison/, it's clear to me that this blog has a lot of good ideas.
But after reading several posts, and Mr. or Mrs. dmbarbour's repository, I really have no idea what "the next step" is, WRT global shared mutable state and stuff. like any libraries that expose this model of programming in Haskell. Or a post with more concrete examples.
The author seems to be working on awelon (written in Haskell), a programming... Language? Environment?
I may be misunderstanding, but something like: "the global store is memcached or the file system or whatever, here are some primitives and combinators for accessing different parts of the global store, don't define functions the normal way but instead do it in this special way to minimize local state" or maybe "here is this new type, it's like a Reader or a State, and you want every function you define to have it as its return type, but somehow it's not a huge pain because of this novel contribution". etc.
anyways, if anyone has any insight, that would be appreciated.submitted by sambocyn
[link] [7 comments]
I'd quite like to learn how to make Haskell powered websites and I'm having trouble deciding which framework to use. Thanks in advancesubmitted by destructaball
[link] [91 comments]
My current approach for backwards compatibility with older ghc/base versions is to have a custom prelude, that contains some CPP and other nastiness, for example: https://github.com/sinelaw/infernu/blob/master/src/Infernu/Prelude.hs I was wondering if there's a cleaner solution...submitted by sinelaw
[link] [9 comments]
Almost a year into Haskell as a hobbyist I have two general thoughts that I think are related and I wanted to get some opinions on them.
Having now written it out, this seems a bit rant like and it's kind of long. The TL;DR is: (1) we don't seem to have a generalized typeclass for some things, e.g. no MonadMaybe, and (2) when it comes to IO I can compile code that will crash at runtime due to an exception, when even Java won't let that happen. Finally (3) is my understanding correct / is there some way of addressing this?
I recently noticed that there are two general "types" of Monads (with a whole bunch of exceptions and variations). The first is SomeMonad a that is specifically about the a. A Tree a, Maybe a, [a], ST s a etc. While the second is a Monad to which the a can often be superfluous, Reader r (), State s (), Writer w () etc. With some that skirt the line (IO, Iter, Rand). I'm sure there's some formal Category theoretic way of saying that.
For the most part when using one of the second type, they tend to be implemented in terms of a Typeclass e.g. MonadReader or MonadState. This makes using them in a transformer stack very easy without having to worry about littering the code with lifts.
With FTP we seem to have done that with Collections. But we don't really do it with anything else. Suppose you have a Transformer stack MaybeT m a, and inside of that stack you use Data.Map.lookup which returns Maybe a, then you would have to run MaybeT . return over it to get it into MaybeT.
I figured that with EitherT I could use MonadThrow with return and throwM as a generalizer. I discovered however that at some point I'd need to catch the exception with catch ea (\e -> left e). Which left me wondering why there isn't a generalized typeclass for the likes of Either and Maybe. And secondly, why the compiler wasn't telling me that an exception hadn't been caught.
One of the great things about Java was how it forced exception handling. If you call a method that throws an exception, you either have to handle it or your method has to throw the same exception. Which means that somewhere along the call stack you must handle it.
To me one of Java's biggest downfalls is that this isn't more rigid. Lookup functions for example don't tended not to throw a NullPointerException and use of Optional certainly wasn't very wide spread. But because exceptions either had to be handled or bubbled their way up the call stack, when they were present you could always choose when you wanted to address them.
I realised today that Haskell doesn't necessarily handle this very well when it comes to IO. I am able to compile a program that will crash on an exception.
I was looking at the async package today. The first thing I noticed was the more specialized type signature async :: IO a -> IO (Async a) instead of a generalized async :: MonadIO m => m a -> m (Asnyc a). Then I noticed that the type signature waitCatch :: Async a -> IO (Either SomeException a) which also forces specialization of the error handling to Either. But even if I use waitCatch is there some asynchronous exception that might be thrown in the parent? Can I get any guarantees from the type signature?
More to the point, I can compile my program using just wait and not handle any exceptions downstream at all. If I make a Map with known values the compiler won't let me get away with not handling null pointer exceptions (or pretending they don't exist with fromJust). But the compiler is perfectly happy to let me make a request to an external server that may timeout, give a bad response, or cause some other exception.
How to address it?
Is there some way the compiler can tell me when a process will crash at runtime because an exception hasn't been handled? Obviously I don't want my code littered with try/catch/finally blocks. But even that might be better than deferring the issue to runtime.
Hopefully not too much of a rant. Almost a year into Haskell now and this is the first time this occurred to me. Perhaps I just have some misunderstanding that could be addressed.submitted by TheCriticalSkeptic
[link] [15 comments]