haskell

When destructuring tuples in Haskell, where can the elements be used?

I am reading a tutorial that uses the following example (that I'll generalize somewhat): f :: Foo -> (Int, Foo) ... fList :: Foo -> [Int] fList foo = x : fList bar where (x, bar) = f foo My question lies in the fact that it seems you can refer to x and bar, by name, outside of the tuple where they are obtained. This would seem t...

Does anyone have any recommendations for starting out in functional programming?

I'm looking for some ebooks that will assist in my learning of functional programming. I haven't yet decided which language I will go with, but I've noticed a fair amount of bias towards LISP, Haskell and F# amongst the community on StackOverflow. As yet, I'm unsure which direction I will take, but can anyone recommend any particular e...

How to catch arbitrary exception in Haskell?

In ghc 6.10.1. ...

Function application: Why is $ used here?

A while ago, I asked a question about $, and got useful answers -- in fact, I thought I understood how to use it. It seems I was wrong :( This example shows up in a tutorial: instance Monad [] where xs >>= f = concat . map f $ xs I can't for the life of me see why $ was used there; ghci isn't helping me either, as even tests I do...

Are there any good examples on how to use Haskell monad functions?

Haskell monad functions are not easy to understand, where can I find usage examples? ...

How to reduce memory usage in a Haskell app?

I am new to functional programming, and now learn Haskell. As an exercise I decided to implement the explicit Euler method for 1D linear diffusion equation. While the code below works correctly, I am not happy about its performance. In fact, I am concerned with memory consumption. I believe that it is related to lazy evaluation, but cann...

When to exploit type inference in Haskell?

I'm curious as to how often experienced Haskell programmers really use type inference in practice. I often see it praised as an advantage over the always-explicit declarations needed in certain other languages, but for some reason (perhaps just because I'm new) it "feels" right to write a type signature just about all the time... and I'm...

Distinctive traits of the functional languages

It is known that all functional languages share some basic properties like using functions as basic building block for programs with all the consequences like using recursion instead of iteration. However, some fundamental differences also exist. Lisp uses a single representation for both Lisp code and data, while ML has no standard repr...

Uses for both static strong typed languages like Haskell and dynamic (strong) languages like Common LIsp

I was working with a Lisp dialect but also learning some Haskell as well. They share some similarities but the main difference in Common Lisp seems to be that you don't have to define a type for each function, argument, etc. whereas in Haskell you do. Also, Haskell is mostly a compiled language. Run the compiler to generate the execu...

Is Scalas/Haskells parser combinators sufficient?

I'm wondering if Scalas/Haskells parser combinators are sufficient for parsing a programming language. More specifically the language MiniJava. I'm currently reading compiller construction and jflex and java cup is quite painful to work with so I'm wondering if I could/should use parser combinators instead. The MiniJava syntax is very sm...

Is there a built-in Haskell equivalent for C++'s std::bind2nd?

What I'm missing is the ability to partially apply the second argument of a function rather than the first. This is especially useful when I want to pass the function to something like map, but without having to write a lambda for it each time. I wrote my own function for this (definition below, just in case there indeed isn't any buil...

What does a pipe in a class definition mean?

class (Monoid w, Monad m) => MonadWriter w m | m -> w where pass :: m (a,w -> w) -> m a listen :: m a -> m (a,w) tell :: w -> m () What is the meaning of the pipe above? The snippet comes from here. ...

Concise Haskell book

In a blog post regarding his JavaScript book, Doug Crockford says I relied on two models when I wrote JavaScript: The Good Parts. The first was Kernighan and Richie's The C Programming Language. It is a brilliant little book. I thought there should be a K&R for JavaScript. When it seems that most tech books are sold by the pound, it ...

Is it possible to change the step size of the built-in haskell range function or literal?

The default [1..5] gives this [1,2,3,4,5] and can also be done with the range function. Is it possible to change the step size between the points, so that I could get something like the following instead? [1,1.5,2,2.5,3,3.5,4,4.5,5] ...

Examining the internals of the functions in Haskell

I am a Haskell newbie, though had a previous Lisp/Scheme experience. Right now I am looking at the examples from SICP and trying to implement them in Haskell to get more hands-on experience. In the lecture 3b authors present a function for computing the derivatives symbolically. It contains, among others, the following lines: (define (d...

c++ to functional

I am wondering how to do this in a functional programming language. Maybe f# or haskell. Can someone show me an example without using any function calls except for find and rfind? This function finds the next slash using i as the num of slash (<0 for backwards). size_t findSlash(const char *sz, size_t i) { std::string s = sz; s...

What are the relative merits of wxHaskell and Gtk2HS?

Which is better for developing GUI applications with Haskell, wxWidgets (via wxHaskell) or GTK (via Gtk2HS)? What are the pros and cons of each? Does it vary depending on which platform you are targeting (I would primarily be working on OS X but would like my programs to work on Linux and Windows too)? ...

How thoroughly should one learn languages like C, ASM, Lisp, Haskell?

Languages like C, Haskell, Lisp, Smalltalk, and assembly language are often touted as things every programmer should know for their effect on the way one thinks about programming, even if they're used very little in real world situations. However, to really learn a language in depth to the point where you know not only the syntax and se...

Can you create more than one element of a list at a time with a list comprehension in haskell?

So, for example, say I had a list of numbers and I wanted to create a list that contained each number multiplied by 2 and 3. Is there any way to do something like the following, but get back a single list of numbers instead of a list of lists of numbers? mult_nums = [ [(n*2),(n*3)] | n <- [1..5]] -- this returns [[2,3],[4,6],[6,9],[8,1...

Using foldl to count number of true values

I'm trying to find a way to do the following function with foldl: count a = length (filter (\i -> i) a) It just counts the number of values that are true in a list of booleans. I did try it myself with count = foldl (\i -> case i of True -> (1+) False -> (0+) ) 0 Which did not even compile. Any suggestion...