News aggregator

My First Haskell Project--Please give feedback!

Haskell on Reddit - Thu, 11/12/2015 - 10:30am

tl;dr: trying to write a blackjack game and it's a mess

This is my first Haskell program bigger than a Project Euler problem and it's not going very well.

I can see places where a monadic solution would be best (mainly passing around various pieces of game state like the deck) but actually implementing one is incredibly unintuitive. The error messages are worse than gcc barfing on C++ templates and it's a choice between a suboptimal solution using lots of temporary names or reading error messages for 2 hours. I think part of the reason the state monad always seems very brittle is that I need to keep packing and unpacking tuples holding each piece of state I need. If I'm not passing just one thing it becomes very verbose very fast. This ends up being more error prone than using mutable state because I have to remember which temporary names go where and typos might not get caught. So I really don't want this to become a bad habit.

The most frustrating part is I'm sure there's a better way to do nearly all of the solutions I came up with but can never seem to achieve the elegance that brought me to Haskell in the first place.

For now the Visibility type isn't actually used for anything, but in the future an AI might operate differently based e.g. on opponents' face up cards.

It's not meant to be a blackjack game that you play but rather to see how different strategies turn out over a lot of games. Right now there's only one (hit below 16, stay above 16) but the idea is I'll write more.

I didn't refactor playGame because even though it should definitely be a lot of smaller functions I think I'm fundamentally messing up big chunks of it (which could be better expressed using a state monad) and would rather learn the proper way to do it.

I really want to like Haskell, it's just that even the most trivial project is excruciating.

I'd appreciate any help and feedback on the code, particularly places I marked with XXX in a comment. I'd especially appreciate help with monads and applicative functors.

Also, does Visibility seem like a monad/applicative functor? It seemed to me like one because of the wrap-unwrap behavior and I think it obeys the appropriate laws, but ?

(Definitely going to break this up into modules but I left it as a single file so it'd be easier to follow for people on phones)

Help and feedback is much appreciated!

submitted by tjakway
[link] [8 comments]
Categories: Incoming News

Designing data structures that are "dependent" on references/pointers. What to do?

Haskell on Reddit - Thu, 11/12/2015 - 7:56am

Is there a general approach for this? Should I just not use Haskell?


I want to create a program for managing and simulating tournaments/leagues in e-sports (and normal sports too, of course).

But I can't figure out a nice way of building the data structure for it. I had so much trouble with it that I resorted to python (which worked out great).

My main problem seems to be that both the winner and loser of a match have to be linked to new matches, and thus every match has two inputs. Here's an example of what is usually called a double elimination group.

player1 --> match -- w --------> winners -- w ---> 1st player2 --> 1 -- l -+ +----> match -- l -+ +-|-+ +-> decider --> 2nd | | +-> match --> 3rd player3 --> match -- w ---+ +--> losers -- w ---+ player4 --> 2 -- l --------> match -- l -----> 4th

This doesn't work well with a typical haskell structure of just holding the data and not referencing other structures. I've had some ideas where you use a builder to create a valid structure and then use an unsafe one underneath, maybe creating a set of arrows and a set of matches or something similar. But that feels like cheating because I'd like the type system to help me construct only valid structures from the start.

Does anyone have any suggestions?

EDIT: Thanks for all the input. I'm gonna try this again with your ideas in mind.

submitted by MaybeJustNothing
[link] [43 comments]
Categories: Incoming News

If Haskell is such a terrible language, what do they program in?

Haskell on Reddit - Thu, 11/12/2015 - 6:41am

I'm an experienced imperative programmer who's been trying to get into Haskell by light studying every now and then for almost 2 years now, and some of the concepts are sinking in, and I love Haskell. I read and try to understand the mathematical foundations as well, and realize that Haskell is not the perfect language (undefined, unsafeCoerce etc.) from that angle, but to my imperative eyes, it seems like a safe haven.

I understand that the language is not for everyone; both for those who don't want to bother with purity and a strong type system and those who desire a language with even stronger mathematical foundations than Haskell. I know what the first group of programmers are thinking, and what languages and tools they're using for their real-life programming problems, but I have no idea about the second group.

I see many people, (type-theorists, category theorists?) bashing Haskell to the ground for its flaws. So, the question is; If Haskell is such a terrible language, what do they program in? I'm sincerely curious about the answer; what do they use to solve real-life programming problems. Do they:

1) Say, "why pretend to be pure and safe while we aren't", then go ahead and use a conventional imperative language?

2) Program in Agda (or the like), even if the "Hello World" program compiles to 20 MBs? (Note that my intention isn't to say anything negative about Agda, I know very little about it, and AFAIK it's not intended to be a "programming" language)

3) Use Agda(or the like) to generate source code for other languages.

4) Prefer one of Haskell's categorical cousins such as OCaml or Erlang because it/they don't have its flaws.

5) (Probably something else I have no idea about.)...

As I said, I'm sincerely curious. Thank you

submitted by enobayram
[link] [84 comments]
Categories: Incoming News

Get a Brain

Haskell on Reddit - Thu, 11/12/2015 - 5:57am
Categories: Incoming News

checking whether the list is active

haskell-cafe - Thu, 11/12/2015 - 5:34am
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion

Image processing

Haskell on Reddit - Thu, 11/12/2015 - 2:59am

I wrote a small proof-of-concept program in Python a while ago which works on jpeg files. I was thinking of working on this again in Haskell.

This program works to select particular photos from a directory of photos. Ideally, I'd like to work with raw files, i.e., .nef files from Nikon cameras etc., since most photographers work with raw files. This by might be a naive question, but is this possible or am I limited to working with jpeg, tiff and png images?

submitted by MyFunc
[link] [6 comments]
Categories: Incoming News

Excuse me, I think this is my stop now...

Haskell on Reddit - Thu, 11/12/2015 - 2:00am

I had been disappointed in the past with other languages such as C++ and Python treading water and stagnating. So this gave me the incentive to look around and discover Haskell.

I only joined the community shortly after Haskell 2010 came to be, and I've learned a lot of mind-blowing things about programming. And for that I'm very grateful to you all!

I was looking forward to a community open to move the language forward given its mantra to "avoid success at all costs" and do the right thing even if it hurts a little.

Haskell's future was looking bright when AMP and FTP were being finally implemented. But this seemed too good to be true. And in fact, people are still complaining about those changes and I'm sure many would rather they were rolled back again.

Also, we have an either absent or contested committee which bows to public pressure by high profile Haskellers who resort to dismissal and hyperbole just to sabotage what's technically the proper thing to do. To be honest, I've started losing faith in the committee myself for becoming conservative (e.g. this 3-year no-warning/cpp policy... wtf).

Given the recent developments I'm afraid Haskell is past its prime (pun intended) anyway. Other languages are moving forward, break things, literature needs updating, people moan, but popularity continues to rise nonetheless. Later generations (often without being aware) then just benefit from the improvements their forefathers fought for rather than blaming them for lost opportunities.

But for some reason, Haskell is held to a higher standard for a much smaller user-base or rather for the prospect of a yet to materialise large user-base. Is this a sign of delusion?

I'm sad about this, but I've been told it's important to walk away when you realise that something isn't working out anymore. So now, I guess, it's my time to vote with my feet (even if I my vote doesn't carry as much weight as Mark's) and seek for greener pastures.

I wish you all the best, and I hope Haskell won't go the way of the Dodo.

submitted by [deleted]
[link] [40 comments]
Categories: Incoming News

Conditionally add OpenBSD's pledge(2) call -- but to which library?

libraries list - Wed, 11/11/2015 - 11:01pm
Hi, I'd like to add the (OpenBSD only) pledge(2) call to some library in our (OpenBSD's) ghc port. See and for some information of what this is about (and Linux people, please don't feel too offended by that second one ;-)) I'd to this as a patch to ghc in our port, but I'd like to eventually submit a patch to include it (conditionally, only on OpenBSD for now) upstream. But I need some hints *where* to include it. At the moment, I'm considering the unix package (bundled with ghc), and therein, the module System.Posix.Unistd. Even if pledge(2) obviously isn't Posix, it's all about stripping down an API which in large parts conforms to Posix to some subset. Would this be acceptable? Or should I use something like System.OpenBSD.Unistd? In any case, client application using it would always either need some #ifdef or would get patches local to the OpenBSD ports t
Categories: Offsite Discussion

I want `go fmt` for Haskell, does anyone else?

Haskell on Reddit - Wed, 11/11/2015 - 10:43pm

hindent chokes hard on whole files, stylish-haskell constrains itself to imports. Given ghc-exactprint coming together, it seems like this should be possible in principle. What's missing? Main sticking point as far as I can tell is compatibility with extensions, but using the GHC API should deal with that issue.

submitted by Mob_Of_One
[link] [60 comments]
Categories: Incoming News

Stack: Copying possible?

haskell-cafe - Wed, 11/11/2015 - 1:37pm
Trying to switch over to stack I copied over ~/.stack to another Linux box And it gives me sanity check failed Machines are same -- both 64 bit ubuntu wily -- user-names are different and that shows in the error message. I'd like to avoid almost a Gb of repeated downloads if possible. But if thats not kosher that fine... Just asking :-) _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion

Using Criterion for throughput benchmarks?

Haskell on Reddit - Wed, 11/11/2015 - 11:50am

The well-known Criterion library is the go-to tool for high-quality performance benchmarking of Haskell code, mainly measuring (and comparing) the time it takes to perform a certain calculation.

This is very useful for a project I'm working on, but being able to turn things (somewhat) around would be even more useful:

  • Instead of hard-coding several benchmarks, it'd be useful if a user could pass certain benchmark parameters as command-line arguments, something which Criterion's defaultMain doesn't support, as far as I could see.

  • Furthermore, for this application, average (or whatever) execution time of an iteration of the algorithm is useful information, but turning this around into throughput (i.e. the algorithm works over multiple megabytes of input data, so turning execution time into MB/s, even if this result would be an extrapolation), would be useful in reporting. Criterion doesn't seem to support custom reporting values though.

Has anyone ever done something like the above?

submitted by nicolast
[link] [7 comments]
Categories: Incoming News