haskell

How do I convert a variable to a string?

For example so that it works like this toString (Var x)= "x" ...

What type of scope does Haskell use?

I'm trying to figure out if Haskell uses dynamic or static scoping. I realize that, for example, if you define: let x = 10 then define the function let square x = x*x You have 2 different "x's", and does that mean it is dynamically scoped? If not, what scoping does it use, and why? Also, can Haskell variables have aliases (a diff...

When is the difference between quotRem and divMod useful?

From the haskell report: The quot, rem, div, and mod class methods satisfy these laws if y is non-zero: (x `quot` y)*y + (x `rem` y) == x (x `div` y)*y + (x `mod` y) == x quot is integer division truncated toward zero, while the result of div is truncated toward negative infinity. For example: Prelude> (-12) `quot`...

Haskell Interactive

I am a bit rusty on my Haskell and am looking to ramp back up. One thing I enjoy from F# is the F# Interactive shell integrated with Visual Studio: I can evaluate virtually anything (including function and class definitions) and use F# as a shell. Is there an equivalent in Haskell? When I use ghci, I cannot evaluate function definitions....

Books, tutorials, references on Haskell for experienced functional programmer

I want to collect a list of handy references on Haskell, that would be useful when one needs to be refreshed about the basic and mundane or move to more advanced materials. In terms of books, Real-World Haskell doesn't seem to fit the bill, because it's moves a bit slowly. On the other hand, I like Programming in Haskell. Even though it...

Haskell Function Application

A bit of a neophyte haskell question, but I came across this example in Haskell's tutorial examples. For "find the last element of a list" there are some obvious versions, like last' [x] = x last' (_:xs) = last' xs But I can't make sense of an alternate version presented: myLast' = foldr1 (const id) So, in trying to make sense o...

Clojure vs Haskell for web applications?

I want to learn a functional language that will be good for building web applications in the future. I am choosing between Clojure and Haskell. Which one is a better choice for my purpose? ...

Explanation of “tying the knot”

In reading Haskell-related stuff I sometimes come across the expression “tying the knot”, I think I understand what it does, but not how. So, are there any good, basic, and simple to understand explanations of this concept? ...

GHC + wxHaskell on Windows

Have GHC 6.8.3 and wxHaskell-0.10.3 on a Windows XP computer. Installed both as binary distributions, not by building from sources. Built a sample with the following command: ghc --make Paint.hs It works on that same computer it was built on (with GHC and wxHaskell installed), but fails if transferred to another one (with neither of th...

C stack overflow on Project Euler Problem 27

I just have started to learn Haskell and combine reading books and tutorials with solving problems from Project Euler. I have stuck on Problem 27 because I get "C stack overflow" error using this code: euler.hs divisors n = [x | x <- [1..n `div` 2], n `mod` x == 0] ++ [n] is_prime n = divisors n == [1, n] f a b = [n^2 + a * n + b | n ...

Turn this recursive haskell function into a map call

This is my code: type HoraAtendimento = (String, Int, Int) htmlHAtendimento :: [HoraAtendimento] -> Html htmlHAtendimento [] = toHtml "" htmlHAtendimento ((da,hia,hfa):[]) = toHtml da +++ "feira " +++ show hia +++ "h - " +++ show hfa +++ "h" htmlHAtendimento ((da...

Where do theses values come from in this haskell function?

I my last question about haskell, the answer provided gave me another doubt... Instead of using the somewhat complex function in my other question, here's a simpler example: sumAll :: [(Int,Int)] -> Int sumAll xs = foldr (+) 0 (map f xs) where f (x,y) = x+y Calling sumAll [(1,1),(2,2),(3,3)] the output will be 12. What I don't unde...

Convert haskell Int with leading zero to String

Suppose I have a variable of type Int = 08, how can I convert this to String keeping the leading zero? For instance: v :: Int v = 08 show v Output: 8 I want the output to be "08". Is this possible? ...

How long does it take for you to be comfortable with Haskell?

I'm an OK C/C++ programmer. I find Haskell very intriguing. But it seems to me, that although it's relatively easy to write clean Haskell code, as it mimics math (which I'm very comfortable with) pretty well. It's very hard to write clean code in Haskell that runs fast. A faster version of quicksort of Haskell is very long and scary, wh...

How do you do generic programming in Haskell?

Coming from C++, I find generic programming indispensable. I wonder how people approach that in Haskell? Say how do write generic swap function in Haskell? Is there an equivalent concept of partial specialization in Haskell? In C++, I can partially specialize the generic swap function with a special one for a generic map/hash_map cont...

What are some good Haskell Primers/Tutorials for beginners?

What are some good links for diving into Haskell and functional programming in general? ...

Turn these haskell Int lists into a different one

I have the following Int lists: t1 = [1000, 1001, 1002, 1003, 1004] t2 = [2000, 2001, 2002] t3 = [3000, 3001, 3002, 3003] The lists size are variable, they are not just 3 like in this example. They can have 1 element or many more. Then I have this: tAll = [t1, t2, t3] I need a function that "turns" tAll into something like this: [...

Restricting a monad to a type class

In Haskell, is there a way to restrict a monad M a so that a satisfy a type class constraint? I am translating the probabilistic modeling example from F# to Haskell. However, in Haskell, I omitted support because it would change data Distribution a to data (Ord a) => Distribution a. With this change, I get the following error: ...proba...

Implications of foldr vs. foldl (or foldl')

Firstly, Real World Haskell, which I am reading, says to never use foldl instead of foldl'. So I trust it. But I'm hazy on when to use foldr vs. foldl'. Though I can see the structure of how they work differently laid out in front of me, I'm too stupid to understand when "which is better." I guess it seems to me like it shouldn't real...

Haskell, Lisp, and verbosity

For those of you experienced in both Haskell and some flavor of Lisp, I'm curious how "pleasant" (to use a horrid term) it is to write code in Haskell vs. Lisp. Some background: I'm learning Haskell now, having earlier worked with Scheme and CL (and a little foray into Clojure). Traditionally, you could consider me a fan of dynamic lang...