Anyway, apologies if this does not belong here, but I'm stuck on a problem and I can't seem to figure it out and it finally occurred to me to ask you guys for help.
Here's a gist of a module I built yesterday in order to pull and count IP addresses from Django Tracebacks.
I can use it on the REPL (GHCi) and get results that I expect in the following way:unlines . map flatten . countUnique . ipOnly . spammers <$> readFile "tracebacks.txt"
However, I can't seem to figure out how to organize the main block. It compiles but does not seem to do anything with input or output (I was hoping to name an infile and outfile on the command-line). Someone here will probably see right away what I'm doing wrong.
In addition, I would be happy to take any other suggestions or critiques you might have of this small script. I crammed a lot of stuff in there in order to experiment with the language a bit, but I'm sure there are mistakes or poor assumptions I have made. In fact, I noticed a discussion today talking about using Data.Text instead of String (which I am relying on pretty heavily here), so I was thinking of rewriting this using Data.Text.
Thanks for any suggestions you might have.
EDIT: I updated the gist with a working main, but I realize now I should probably have kept it broken for people who come to this thread late. The first version can be seen in the revision history: https://gist.github.com/pellagic-puffbomb/324cf7f50f4480e8a8d1/revisionssubmitted by erewok
[link] [18 comments]
I'm writing a small program (an extension of a Pokemon game that got posted here a while ago) where I'm trying to not use IO as much as possible. The program relies on randomness (picking a random Pokemon and move) and on writing (say things like "Pokemon X attacked you for Y damage!").
Again, I'm trying NOT to use IO, so instead I'm using Rand (Control.Monad.Random) and Writer. Now, I have a couple of functions that return Rand g a (where a can be a pokemon name or move), but I would like to "log" the name and move after they come in.
Here's a simplified version of what I'm trying to do:battle :: _ battle = do move <- getRandomMove -- returns an Rand g Move tell ["Pokemon attacked you with " ++ name move] damage <- calculateDamage -- returns an Rand g Damage tell ["And did " ++ damage] battle
Of course, this doesn't work (I'm mixing my Rands and Writers). I thought "maybe this is what Transformers are for?"). I tried using WriterT and RandT in a combination of ways, but I always go stuck, which makes me think that's not right either.
So my question are:
- Are transformers the answer to my problem?
- If so, how do you use them? (I'm failing to understands them from the tutorials I've found online)
- If not, how could I solve this problem?
Edit: Formatting Edit2: battle is recursivesubmitted by Die-Nacht
[link] [13 comments]
We have a number of openings for PhD study at the University of Birmingham, and we also have an imminent funding deadline, so please contact me (or any of us in the theory group at Birmingham) immediately if you're interested.
I personally am looking for students interested in designing the next generation of functional languages. You can find a fuller announcement here.submitted by neelk
[link] [3 comments]
We are excited to officially announce the open source release of our REST framework rest!
If you want to start using rest, check out the tutorial or the example application. You can also come to the Haskell Exchange 2014 where Erik will give a talk about rest. We’d also be happy to answer any questions you have, shoot us an e-mail!
The most important packages are:
- rest-core: A DSL for defining versioned and web server agnostic REST resources. This is the workhorse of the framework
- rest-snap, rest-happstack, rest-wai: Drivers for running resources using the web server of your choice
We have also released other packages that are either used by or can be used with rest:
- rest-client: Used by haskell clients generated by rest-gen
- rest-types: Types used by the other rest packages
- json-schema: Define and derive schemas for JSON serializations
- generic-aeson: Generically derives JSON serializations for data types minimalistically
- regular-xmlpickler: Generically derives XML serializations for data types
- aeson-utils: Utilities for working with Aeson.
- hxt-pickle-utils: Utility functions for using HXT picklers
- multipart: HTTP Multipart implementation forked from the cgi package
- rest-stringmap: Maps with string-like keys with built-in serialization to XML and JSON (since JSON doesn’t allow arbitrary keys)
- code-builder: String manipulation library for code generation
We had a great time working on rest at ZuriHac (thanks for organizing, Better!) and we are happy to see that a lot of people were interested in our work. We got a lot done, here are some highlights:
- Erik wrote an introductory tutorial to rest
- Håkan Thörngren rewrote the rest-gen Haskell code generator to use haskell-src-exts, it was released in rest-gen-0.14
- Christian Berentsen did several things:
- Cleaned up the interface of json-schema, it was released in json-schema-0.6
- Added support for outputing Fay compatible json as a separate output type (we want to make it easier to extend rest with more output types so things like this can go in external packages)
- Implemented a generic API discovery resource that you can hook into your API with no configuration
- Tom Lokhorst helped out with some always appreciated bug fixing
- Sebas wrote the rest-wai driver to make sure everyone can use the web server they prefer together with rest
- Adam worked on the rest-example application and rewrote parts of rest-gen to make the code generator and the library interface simpler
- wiz did performance benchmarks and created a script to generate haddocks for rest itself
I hope I didn’t forget anyone. A big thanks to everyone who participated!
All the mentioned projects are available on hackage and in public repositories on github. We also created a public mailing list for all our open source projects.We use these packages to write our Haskell API code for Silk.
Join our team if you enjoy this stuff too, we’re hiring!