Learning haskell, I wrote this simple function that's supposed to return a list of prime numbers up to n. It works for low enough n, but above 5000 or so, it becomes noticeably slower to begin, which is far lower than a prime sieve has any right to slow down. What am I missing?import Data.List sieve :: (Integral a) => a -> [a] sieve n | n < 2 =  | n == 2 =  | otherwise = comb [2..n] where comb xxs@(x:xs) | x^2 > last xs = xxs | otherwise = x : comb (xs \\ [2*x, 3*x .. n]) comb  =  submitted by ZankerH
[link] [21 comments]
I started working on an emulator for the old CHIP-8 CPU as a project to learn haskell. Although it probably wasn't the best choice of project due to how basic it is, I've definitely gotten hooked on haskell.
I've done a few clojure projects in the past, so I'm familiar with the functional programming basics, but I haven't experimented much with haskell's abstractions (apart from basic monads).
If anyone can offer any improvements or tips, i'd be greatly appreciated. I'm planning on doing plenty more haskell projects, so I'd like to nip any bad practices in the bud.
Thanks in advance!submitted by tominated
[link] [3 comments]
Hey everyone. I've just started out with Haskell, and I just can't seem to understand how the reader and writer monads work. Could someone point me to some place where they're explained well? Thanks!submitted by Bollu
[link] [15 comments]
[ANN](and feedback request) unagi-chan: Fast and scalable concurrent queues for x86, with a Chan-like API
Here in sunny Austin Texas we've spun up a Haskell meetup group, and if you're in the area, you should join! Specifically, we've set up a small meetup tomorrow as a training class to help people solidify and expand their Haskell knowledge.
We currently are having monthly meetups here with classical talks, and we're also planning of setting up monthly or biweekly study groups like the one tomorrow for people to talk and learn in a different setting. So the one tomorrow will hopefully be the first of many more to come.
Tomorrow the study group will be downtown at MakerSquare - and if you're in the area, you should come by! Brand new to Functional Programming? Don't have GHC installed? Don't even know what Haskell is? No matter - things will happen, people will learn things, and you should come by and learn how awesome it is and how awesome all of us are, and we'll help you as much as we can.
Next week we'll be having a meeting at Rackspace in North Austin, where we'll be talking about error handling in Haskell, and I'll probably talk about something and I have no idea what that will be yet (it'll be a secret).
We normally have a turnout of about 20 people for the meetings. But that's just because you haven't come and hung out yet. The meetings are typically open forum and rather lax. So you're encouraged to raise your hand or just speak up.
We also tend to go drink beers and talk into the night afterwords - with many riveting conversations, including subjects like (roughly in order of priority):
- Tacos. Beer. Serious business.
- Why is software so terrible?
- How to achieve world domination in a purely-functional way?
- Education and how to do that properly.
- War stories (tears of joy/pain are encouraged)
- Cloud computing (the half-dozen Rackspace employees love this one!)
- Ask Austin (me, not the town) how some random GHC thing works.
- Non-taco-related foods.
Also, a bajillion points go to Rackspace for giving us a great working space for our meetups so far and providing us with great pizza for the past several meetings.submitted by aseipp
A new draft paper, Resource-dependent Algebraic Effects, is available. Abstract:
There has been significant interest in recent months in finding new ways to implement composable and modular effectful programs using handlers of algebraic effects. In my own previous work, I have shown how an algebraic effect system (called “effects“) can be embedded directly in a dependently typed host language. Using dependent types ought to allow precise reasoning about programs; however, the reasoning capabilities of effects have been limited to simple state transitions which are known at compile-time. In this paper, I show how effects can be extended to support reasoning in the presence of run-time state transitions, where the result may depend on run-time information about resource usage (e.g. whether opening a file succeeded). I show how this can be used to build expressive APIs, and to specify and verify the behaviour of interactive, stateful programs. I illustrate the technique using a file handling API, and an interactive game.
I’ve just submitted this, although constructive comments and suggestions are still of course very welcome!
I've been wondering about this for a little bit:
Q: When is it more convenient to use a Reader Monad as opposed to just threading an argument through your program?
I.e. what is the advantage of:f :: String -> Reader Config SomeType -- vs g :: String -> Config -> SomeType
One advantage I've seen is that if you don't annotate your functions with type signatures and use the Reader Monad with type inference, you can change the type of the shared environment without having to update much code (except code that pulls out of the shared environment, but that can be factored out and shared as well). Is this the only advantage? The disadvantage to this approach, imo, is you lose the nice readability you get from explicit type signatures.
On the other hand, if you need to introduce a dependency, you can just thread it through your function via plain-old arguments. What do you lose with this? Is it that you must update all functions that depend on modified methods, and programming in a monadic style may avoid some of these explicit refactorings?
Perhaps using the Reader Monad becomes more handy in large code-bases?
PS - my apologies if I'm not articulating this well.
Edit: thank you everyone. The consensus as I understand it seems to be (upstream/downstream refer to a methods call graph):
- Reader monad allows environment-independent methods from having to manage the environment for downstream dependencies.
- Reader monad is safer (you cannot manipulate or change the environment in an upstream method)
- MonadReader class makes working with Reader monad nice .
[link] [16 comments]
For my summer project, I’d like to learn Haskell by implementing a Python 3 interpreter. I’m evaluating options for parsing, specifically the whitespace sensitivity part. Either:
- Alex + custom lexer pass to accommodate indent tracking + Happy (conventional approach)
- Parsec + indents package
I started with Parsec, but got burned by it’s lexeme function eating newlines. Right now I'm using Alex + Happy, and wishing I had the help of idents. I’m more familiar with traditional yacc-esque LALR parser generators, so there's a comfort using them. (Since Python's grammar is LL, I believe it means Parsec is a viable option.)
Any advice on what to go with here?submitted by mattygrocks
[link] [4 comments]
Hello, as a practice exercise I decided to code a sliding puzzle solver (like 8-puzzle or 15-puzzle). Now, the solution is there and it is working but the problem I face now is the runtime. I would like to request some help with optimising the solution (if at all possible). I'm interested to see what steps one could take to improve performance of their Haskell program.
My implementation can be found here: https://gist.github.com/anonymous/166d8a3323a3f96eab04
Sample input file:4 5 4 3 8 9 2 6 1 0 13 14 7 15 11 10 12
If you run it under the profiler you will see that the amount of data we generate is about 9Gb. And the "problematic" functions are manhattan and boardDistance. I'm currently clueless about how to tackle these functions to optimise them (if at all possible). Seeking for your help!
Thankssubmitted by faorien
[link] [11 comments]
I’m xxxxx from Facebook’s recruiting team. I found your profile on Github and Haskellers and think that you could be a great match for Facebook.
We are currently looking for Senior Software Engineers to join our London office and work on products such as Search, Mobile Engineering, Developer Platform, Security, Site Integrity, etc.
Your passion for Haskell really caught my attention :)
Would you be interested in having a conversation about the opportunities at Facebook London that might be of interest to you?
If you are interested, let me know a day/time that suits and we can organise a time to talk.
The funny thing, is I got an almost identical email from google a while back. These are all sent out as template letters.
Actually, I think that this isn't a great thing. This is zero barrier recruting. They didn't look at my code and chances are they'd stop being interested the second they saw my resume. I don't yet have enough experience working in a group to work as a senior engineer. I have about 12 hours work experience. It doesn't cost them anything to send out these emails en-mass. But it probably costs a lot of young developers time and stress trying to respond to them only to find later that the interest wasn't meant seriously.submitted by timthelion
[link] [35 comments]
Please go through it and tell me anything that can be done more elegantly. Thanks in advance.submitted by kmspriyatham
[link] [5 comments]