News aggregator

Small Crash-Course for Haskell

Haskell on Reddit - Wed, 07/01/2015 - 11:55am

Hey all,

About a year ago a few friends of mind were interested in learning Haskell, so I put together a few blog posts to serve as a "crash-course". I've only now gotten around to putting them online, but they cover the basics of syntax, using cabal, typeclasses and Prelude typeclasses, and some of the more abstract ones as well. These won't really be great for everyone since I wrote them with a few specific people in mind, but perhaps someone will enjoy them!

Intro to Haskell Syntax

Intro to Cabal/Gloss



Finger Trees -- this one is an older one, maybe even has been on this sub before.

If you find any errors (logical or formatting), please let me know!

submitted by NiftyIon
[link] [10 comments]
Categories: Incoming News

Use verbs or adjectives/properties to name functions?

Haskell on Reddit - Wed, 07/01/2015 - 9:51am

Considering Haskell uses call-by-need evaluation, you are never really applying a function to anything. All your code describes what things are and not how they are computed.

For example,

map :: (a -> b) -> [a] -> [b] map _ [] = [] map f (x:xs) = f x : map f xs

The name "map" acts like a verb, as if the code were "mapping" the function over a list. But, actually, the code is just describing how a new list of "b" can be produced out of a list of "a" and a function "a -> b". Would a name like "mappedBy" make more sense?

mappedBy :: [a] -> (a -> b) -> [b] [] `mappedBy` _ = [] (x:xs) `mappedBy` f = f x : xs `mappedBy` f

I see Haskell library uses verbs and adjectives (or "properties") to name functions. There is no standard or "correct" way to name stuff?

Other examples:

insert :: Ord a => a -> [a] -> [a] -- verb style insert x xs = ... with :: Ord a => [a] -> a -> [a] -- adjective/property style xs `with` x = ... length :: [a] -> Int -- adjective/property style length xs = ... getLength :: [a] -> Int -- verb style getLength xs = ... sort :: Ord a => [a] -> [a] -- verb style sort xs = ... sorted :: Ord a => [a] -> [a] -- adjective/property style sorted xs = ... sortBy :: (a -> a -> Ordering) -> [a] -> [a] -- verb style sortBy f xs = ... sortedBy :: [a] -> (a -> a -> Ordering) -> [a] -- adjective/property style xs `sortedBy` f = ... on :: (b -> b -> c) -> (a -> b) -> a -> a -> c -- adjective/property style f `on` g = ... applyBeforeAndThen :: (a -> b) -> (b -> b -> c) -> a -> a -> c -- verb style applyBeforeAndThen g f = ... submitted by evohunz
[link] [8 comments]
Categories: Incoming News

Mark Jason Dominus: The annoying boxes puzzle

Planet Haskell - Wed, 07/01/2015 - 9:13am
Here is a logic puzzle. I will present the solution on Friday.

There are two boxes on a table, one red and one green. One contains a treasure. The red box is labelled "exactly one of the labels is true". The green box is labelled "the treasure is in this box."

Can you figure out which box contains the treasure?

The treasure is in the red box
The treasure is in the green box
There is not enough information to determine the answer
Something else:
Starting on 2015-07-03, the solution will be here.
Categories: Offsite Blogs

Why does `sort` in Data.Discrimination claim to be O(n)?

Haskell on Reddit - Wed, 07/01/2015 - 9:04am

The documentation for Data.Discrimination has:

sort :: Sorting a => [a] -> [a] O(n). Sort a list using discrimination.

What's the trick?

submitted by clrnd
[link] [19 comments]
Categories: Incoming News

Container or Nix configuration with latest and greatest GHC, emacs, and emacs packages?

Haskell on Reddit - Wed, 07/01/2015 - 8:31am

Hey guys,

I'll get to the point. I use emacs. I use this guide to set up emacs. Things had been working pretty seamlessly for the past few months. Then they stopped working so great. I started getting weird errors. Whereas it used to look like this now it looks like this.

I don't want to have to mess with this. I've contemplated just uninstalling everything, reinstalling haskell-platform, recompiling GHC, reinstalling emacs, downloading all of the emacs packages, etc.

Problem: I don't want to have to do this shit every time emacs messes up on my 3 different devices I work on.

Solution: I'm going to write a bash/python script that does all of it for me.

Question: Has this already been solved? Is there like, a container or Nix config file that does all of this for me already? It would be great if so.

submitted by socratesthefoolish
[link] [4 comments]
Categories: Incoming News

Web Scraping with Lenses

Haskell on Reddit - Wed, 07/01/2015 - 8:23am
Categories: Incoming News

Servant + Persistent With Simple Authorization Checks?

Haskell on Reddit - Wed, 07/01/2015 - 7:28am

/u/bartavelle's recent post on Servant + Persistent (not linking as it seems to tripping up mod filters) and the associated use case is exactly what I am battling with right now. However, most of the article went way above my head so probably won't be attempting that type of solution.

I am dealing with something mundane. a request looks like this:

/user/id/post/id -- get, update, etc.

I do two things: (1) Does the auth token header match the session for the user-id (2) does user-id own post-id.

I return a boolean if it fails. Without worrying about this failure, I specify all my business logic, which can also fail so will return a Maybe at the end. I finally check for the failure pair: if it is (Failed, _) -> I return an unauthorized http status. If it is (_, Failed) -> I return business logic failure response. Otherwise, I return the expected response JSON. I am counting on Haskell's laziness to not evaluate the business logic as any first failure can ignore evaluating the business logic (probably risky?)

This means at the top of all my handlers, I have 2-3 lines of authorization checks. My beginner Haskell brain felt, it will be nicer if there was a combinator in servant, that will take a function (similar params as the handler and return Accept / Reject). This way we can create something like

"user" :> Capture "uid" UserId :> Header "Auth-Token" Text :> Get '[JSON] User :>> MyAcceptRejectFuncType UserId Text

Servant can then first call myAcceptRejectFunc with uid and auth-token and if it says Accept, then it will invoke the regular handler with all the params. Otherwise it will just cut short the request to the client.

Of course, this also leads to some boiler plate because you will want to verify user-id and comment-id too so you will have 2 separate functions verifying ownership. Although, this can probably only be generalized by the app so may not be something servant should worry about.

Is it possible to specify such a chaining logic in servant in a clean manner? Is it even a good idea?

submitted by lleksah15
[link] [5 comments]
Categories: Incoming News

Survey: Which Haskell development tools are you using that make you a more productive Haskell programmer ?

Haskell on Reddit - Wed, 07/01/2015 - 6:59am

1) Are you using Leksah, ghc-mod, hasktags, hoogle, vim/emacs/atom/sublime (plugins)/FPComplete online IDE or something else ?

2) How useful do you think the tools you are using are?

3) What are they useful for you?

4) What problems do they help to solve for you ?

The goal of this question is to get an idea about the current status of Haskell development environment tools, their popularity and percieved usefulness.

This question is NOT about package management/cabal hell. It is purely about writing and reading Haskell code. So to keep the tread tidy and focused please do not comment on package managment and similar tools like nix, halcyon, docker, cabal sandboxes, etc.

I have personally tried Leksah and haskell-vim-now, both seem to be pretty helpful, especially when reading some else's code. The possibility to jump to definition of a given identifier is very handy.

I have also tried sublime,atom,intellij plugins for haskell , respectively and FPComplete online IDE. They did not seem to be as powerful IMHO as Leksah or haskell-vim-now.

I have not tried Emacs.


Emacs + Haskell specific plugins : 14

Vim + Haskell specific plugins : 3.5

Selected quotes:

hdevtools :

"I like the speed of hdevtools but I do not like that type inspection doesn't work on source files with errors. That makes it difficult to use holes productively."

ghc-mod :

"ghc-mod is vital, working without it feels like having a hand tied behind my back. Seeing type errors without the need to compile and being able to inspect types under the cursor is vastly more efficient."

"Also is it just me, or does ghc-mod basically always fail to guess the type?"


"ghci-ng and haskell-mode with proper goto-definition, get any subexpr type, quick type-checking and jump to error, and more are a life-safer for me."

submitted by jocomoco
[link] [143 comments]
Categories: Incoming News

Philip Wadler: The Thrilling Adventures of Lovelace and Babbage

Planet Haskell - Wed, 07/01/2015 - 4:29am
Sydney Padua explores an alternate universe wherein Ada Lovelace and Charles Babbage complete the Analytical Engine and use it to (at the order of Queen Victoria) fight crime. I've blogged before about the web comic, but the book is even better.

Padua's tome reconciles hilarity with accuracy. I am not normally a fan of footnotes: if it is worth saying, say it inline; don't force your poor reader to break the flow of thought and eye, and leap to the bottom of the page. But here is the glorious exception, where the footnotes supplement, argue with, and occasionally threaten to overflow the comic. Even the footnotes have footnotes: endnotes cite sources for the dialogue, present pocket biographies of Ada and Charles' contemporaries Isambard Kingdom Brunel, Charles Dodgson, and George Boole, quote at length from original sources, and explain the workings of the Analytic Engine. In the midst of an illustrated fantasia riff on Alice in Wonderland, the footnotes pursue an academic war as to whether or not Babbage truly considered Lovelace to be the Empress of Number. Padua makes pursuit of Victorian arcana a thrilling adventure of its own. Highly recommended!

Categories: Offsite Blogs

How do you compute a histogram in a pure language?

Haskell on Reddit - Wed, 07/01/2015 - 4:23am

I found this interesting question on Yossi Kreinin's blog: how do you compute a histogram in a pure language? More concretely, you're given an integer n and an array (or list) of integers less than n, and you need to return another array (or list) of length n, where the kth element is the number of elements in the original array which are equal to k.

The simplest implementation in an imperative language would look like this:

for (int i = 0; i < array.length; i++) histogram[array[i]]++;

On the other hand, in a pure language the simplest implementation would probably use a map or functional array, with logarithmic update time.

I'm aware of things like linear types, ST, IORefs, etc. But it would be interesting to have a solution that matched the imperative version in complexity while being pure "in spirit", not just "in letter". Does such a solution exist?

EDIT: the most relevant answer was given by /u/edwardkmett in this subthread. It looks like the problem is open, i.e. there's no known algorithm that fits my bill, but no proof that it's impossible either.

submitted by want_to_want
[link] [124 comments]
Categories: Incoming News

Douglas M. Auclair (geophf): 1HaskellADay June 2015 Problems and Solutions

Planet Haskell - Wed, 07/01/2015 - 3:38am
June 2015
  • June 30th, 2015: Count Dracula has just enough time for a quickie, and today's #haskell problem <iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="" frameborder="0" height="266" src="" width="320"></iframe>Count Dracula: "Vithd you, never a quickie ... alwayz a longie! Bla-blah-blaaaah!" ... and the solution
  • June 29th, 2015: Toodle-pip! Word-frequency of a novel purportedly written in 'Hinglish, don't you know!' Today's #haskell problem That solution is SO my bag!
  • June 26th, 2015: THUGs hate code duplication. I bet you didn't know that about THUGs. #thuglife With today's #haskell problem, you do. The solution is awesome, because reasons.
  • June 25th, 2015: We solve today's #haskell problem like a Thug. A CANADIAN Thug … #ThugLife When a THUG wants a cup-o-joe, it just makes sense to give'm dat cup-o-joe when he throws down dat Hamilton #thuglife
  • June 24th, 2015: Today's #haskell problem shows us Mad Dad is Sad ... … ... AND CANADIAN! AND SO ARE YOU! #whendidthathappen
  • June 23rd, 2015: Banana Fish! I don't know what that means, but: (I also don't know what map 'a'-"apple" 'b'-"banana" means, either). Dad even got the banana WITH TAXES! But is Dad happy? Oh, no! See today's problem (forthcoming)
  • June 22nd, 2015: A couple of range-like thingies for today's #haskell problem 'Thingies' is a technical term. Arrows for ranges? Who knew that could be a 'thing'? (Again, technical term. It means: 'thing.')
  • June 19th, 2015: 
♫ Grease is the word,
is the word,
is the word,
that you heard,..
... and is today's #haskell problem. #graph O! What a tangled web we weave! Contracts between corporations #graph Using #neo4j to show complex interrelationships between corporations #haskell
  • June 18th, 2015: Graph owners of companies ... LIKE A BOSS for today's #haskell problem def #NSFW-youtube-link: <iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="" frameborder="0" height="266" src="" width="320"></iframe>Take this #graph and shove it; I don' work here anymore! A solution
  • June 17th, 2015: What does Hannibal Lecter have to do with today's #Haskell problem? Well, actually nothing. Good for name-dropping ;)<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="" frameborder="0" height="266" src="" width="320"></iframe>Ooh! pritti colours! Lines and circles! ME. LIKEY! Visualizing relations between companies and their employees in #neo4j #graph database #bigdata
  • June 16th 2015: Business. Commerce. Relationships. And the plot thickens for today's #haskell problem You scratched my back, so the solution will scratch yours:
  • June 15th, 2015: We're told to 'mind our own business.' For today's #haskell problem, however, we don't. If all the world were 450 businesses ...huh, don't know how to end that couplet, so I'll just share the solution:
  • June 12th, 2015: Today's Haskell problem is really simple: Write a Haskell Database. ;)
  • June 11th, 2015: A mapping of a map of categories to various sets of symbols. Not at all a Graph. Nope. Not at all. So, forewarning: there is wootage to be found in the solution 
  • June 10th, 2015: FREE LATIN LESSONS with today's #haskell problem! AND curl, but as long as you don't sudo bash you should be okay ...
  • June 9th, 2015: LET'S PRETEND! that today is yesterday, huh? So 'today's #haskell problem is about Options Trading ... not really.
  • June 8th, 2015: Improving the accuracy of the stddev modifier is the topic for today's #haskell problem
  • June 5th, 2015: Today's #haskell problem is kinda from Haskell by Example Maps don't love you like I love you 
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="" frameborder="0" height="266" src="" width="320"></iframe>Hey, did you just make a map from a map and a multimap? Is that even allowed? Yes, ... yes, it is.
  • June 4th, 2015: Peano's big TOE has a #haskell problem for you today, rollin' on the river Types can be ... helpful in modeling solutions. Yeah.
  • June 3rd, 2015: As we're not going to do switch for today's #haskell problem (Why? BECAUSE I SAID SO), let's deredundancify an array. An array by any other name is just a graph ... hey, it's possible!
  • June 2nd, 2015: Today's #haskell problem is called 'twixt' and is inspired from a tweet by @jamestanton Betwixt a rock and a prime place lies the solution
  • June 1st, 2015: These factorials are prime for ... primes. Erhm, yeah. Today's #haskell problem from @jamestanton
Categories: Offsite Blogs

Haskell and PVP

Haskell on Reddit - Wed, 07/01/2015 - 3:21am

I think we need to review PVP. In the Versions numbers part, it states this:

A.B is known as the major version number, and C the minor version number.

I know that has been the de facto standard in the Haskell world. However, I don’t understand the use of two digits for the major – understand A.B where A is the supermajor and B is the major. All the packages I have on hackage and stackage have the supermajor set to 0. I also know that a lot of packages never get the supermajor set to anything else other than 0.

So, my point: what is that supermajor for and, a more important concern to me, is it meaningful? We already have patch version for internal non-breaking changes, minor version for non-breaking changes and major for breaking-changes.

I’d also like to point out Semantic Versioning. Why do we all not adopt that? Some people out there tend to use it already – some packages have had several supermajor increments in the past.

What do you think?

Update: looks like there was that exact discussion somewhere else a year ago here. Thank you /u/chrisdoner for pointing that out. ;)

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

Thiago Negri: Haskell is just some steps away from Java

Planet Haskell - Tue, 06/30/2015 - 7:35pm
Start with Java, then:
  1. Forbid using null;
  2. Use only immutable objects, add "final" modifier to everything;
  3. Swap methods by static functions with the the original "this" as the first argument, e.g. "" turns into "bar(foo)";
  4. Add a lot of features to the type system;
  5. Remove type annotations, i.e. "Foo bar(Foo self)" turns into "bar(self)";
  6. Remove useless parens, i.e. "bar(foo)" turns into "bar foo";
  7. Add call-by-need evaluation;
  8. Done, you have Haskell.
It's not that hard, is it?

One, using null references is a recognized bad practice, see "Null References: The Billion Dollar Mistake." Java 8 already provides the Optional type to stop using nulls.

Two, immutable objects are a win strategy, see posts by Hirondelle Systems, IBM, Yegor, and others.

Three, as you only have immutable objects, there is no reason to use methods instead of static functions, considering you maintain polymorphism (not quite the case for Java, but for the sake of this rant, consider as if it has this feature).

Four, improve the type system. The type system used by Java language misses a lot of features. If you don't feel it, just consider this as an added bonus. When you start using the type system features in your favor, you end up with much better code.

Five, imagine the Java compiler could infer the type of the arguments, so you don't need to type them everywhere. You still have the same static typing language, you just don't need to write the types. Shorter code means less liability to haunt you.

Six, why all those parens? Just drop them. Less code to write, hurray!

Seven, call-by-need just makes a lot of things easier (also makes a lot of things harder), but I really think it is a winner when you talk about productivity. When coding, I feel it a lot easier to express things in terms of values instead of steps (mathematicians have been doing this since long before computers). Expressing things in terms of values in a universe without call-by-need will result in a lot of useless computations, so call-by-need is a must.

Eight, done! This is Haskell. No functors, monads, arrows, categories or lists needed.

Why this post? Well, I don't know. It just occurred to me that if you really go into following good coding practices in Java (e.g. avoid null, use immutable objects), you will eventually feel familiar with functional code. Add some more things to the mix, and you end up with Haskell. I think people feel a bit scared at first contact with Haskell (and family) because of the academic and mathematical atmosphere it has, but in the end it is just a lot of good practices that you are kind of required to comply with.
Categories: Offsite Blogs

How to Hijack stdin,err,out, thread safely?

haskell-cafe - Tue, 06/30/2015 - 7:27pm
Hi, I'm currently writing a web app to check the spec of input code usging QuickCheck. quickCheck* functions writes results to stderr & stdout, but I don't want them written to the app's original stdout/err. (I'm using SafeHaskell features to avoid malicious code executed, so don't worry about that :-)) So I want to execute I/O action hijacking stdout/err in a thread-safe manner. For example, I need function like below: censorHandles :: IO a -> IO (a, String, String) censorHandles = ... or withStd :: Handle -> Handle -> Handle -> IO a -> IO a withStd = ...
Categories: Offsite Discussion

Functional Jobs: Senior Developer at Elsen, Inc. (Full-time)

Planet Haskell - Tue, 06/30/2015 - 2:36pm

Elsen is building the next generation of market simulation software at the intersection of high performance computing, machine learning, and quantitative finance. We're a small, tight-knit team located in the financial district of downtown Boston.

We are looking for a senior software developer to help extend our infrastructure which is written in Haskell, C, and Python. Although substantial knowledge of Haskell is desired, we are primarily looking for individuals with demonstrated experience in financial modeling and the ability to implement ideas quickly and accurately.

Some things we look for in an candidate:

  • Open source involvement
  • Deep understanding of quantitative modeling
  • PostgreSQL or similar database familiarity
  • Understanding of various parallelism techniques (threads, software transactional memory, GPUs, distributed computing)
  • Technical analysis with ta-lib
  • Use of iteratee Haskell libraries (conduit/pipes)
  • Experience with modern C development
  • NumPy/SciPy/Pandas experience
  • Open to playing complex board games from time to time
  • Overall fun-loving personality and good sense of humor

Get information on how to apply for this position.

Categories: Offsite Blogs