haskell

absolute values in Haskell

I am trying to write a function that returns the absolute value of an integer... abs :: Int -> Int abs n | n >= 0 = n | otherwise = -n myabs :: Int -> Int myabs n = if n >= 0 then n else -n They both work for positive integers but not negative integers. Any idea why? ...

Good resources on using functional programming in game development?

I'm quite new to that functional programming paradigm, but so far I like it. Since I'm into game development, I want to try it out in writing some games in purely functional programming style. I don't mind the language - be it Erlang, Haskell, Lisp, or even Ruby (I found out it supports functional programming traits). Well, it is obviou...

Merge sort in Haskell

Hi, I am new to Haskell and I am trying to implement a few known algorithms in it. I have implemented merge sort on strings. I am a bit disappointed with the performance of my Haskell implementation compared to C and Java implementations. On my machine (Ubuntu Linux, 1.8 GHz), C (gcc 4.3.3) sorts 1 000 000 strings in 1.85 s, Java (Java...

Common programming mistakes for Haskell developers to avoid?

In the spirit of the other common mistakes in questions, what are the most common mistakes that Haskell programmers make? I've been teaching myself Haskell for a little while and I am starting to feel comfortable enough with the language to start applying it in the real world. ...

Haskell Hello world, eclipse IDE

I'm having trouble getting "hello world" going with eclipseFP and Haskell. I have the following code, module Main where main = putStr "Hello world!" and when I compile it with ghc.exe .\H1.hs -o hw.exe it works fine, but under eclipsePF, when I run it I only see the following in the console window: GHCi, version 6.10.4: http://...

Haskell and Quadratics

Hi, I have to write a program to solve quadratics, returning a complex number result. I've gotten so far, with defining a complex number, declaring it to be part of num, so +,- and * - ing can take place. I've also defined a data type for a quadratic equation, but im now stuck with the actual solving of the quadratic. My math is quite...

Resources for learning category theory

I am going to take a course on category theory soon. What resources can you recommend for learning about it? What parts are relevant to learn and how do I learn to apply my knowledge? ...

Haskell equivalent of Python's "Construct"

Construct is a DSL implemented in Python used to describe data structures (binary and textual). Once you have the data structure described, construct can parse and build it for you. Which is good ("DRY", "Declarative", "Denotational-Semantics"...) Usage example: # code from construct.formats.graphics.png itxt_info = Struct("itxt_info",...

Haskell Parsing Error

So I have finished creating my own complex number data type in haskell. I've also, thanks to another question on here, got a function that will solve a quadratic equation. The only problem now is that the code generates a parsing error in hugs, when trying to solve a quadratic with complex roots. i.e. In hugs... Main> solve (Q 1 2 1)...

Common Haskell pitfalls a newbie should be on a lookout for

I'm thinking of learning Haskell, so I was wondering what issues are often ran into by Haskell newbies (especially ones which haven't had much experience with functional programming). Any other kind of advice for a programmer new to Haskell would be very much appreciated as well. ...

Simplifying some Haskell code

So I'm working on a minimax implementation for a checkers-like game to help myself learn Haskell better. The function I'm having trouble with takes a list for game states, and generates the list of immediate successor game states. Like checkers, if a jump is available, the player must take it. If there's more than one, the player can ...

Printing a result during a recursion in haskell

Hi I am beginning to learn Haskell and am making a program to do the iterative process: n -> n/2 (for even n) n -> 3n+1 (for odd n) So I got this far:` chain n | n == 0 = error "What are you on about?" | n == 1 = error "Finished" | rem n 2 == 0 = chain (n `div` 2) | rem n 2 /= 0 = ...

Finding the leaves of an inductively-defined tree

So, I have a function of type: genTree :: Node -> [Nodes] Given a node, this function generates the set of children of that node in a tree. The function can be applied again to those children to generate their children, until it eventually generates a node with no children, i.e. a node for which genTree returns []. What I'm trying t...

Iterating a function and analysing the result in haskell

Ok, referring back to my previous question, I am still working on learning haskell and solving the current problem of finding the longest chain from the following iteration: chain n | n == 0 = error "What are you on about?" | n == 1 = [1] | rem n 2 == 0 = n : chain (n `div` 2) | otherwise = n : chain (3 * n...

Running a compiled Haskell program; getting errors

Ok, so following on from my previous question I have ended up with the following code: module Main where import Data.List chain n | n == 0 = error "What are you on about?" | n == 1 = [1] | rem n 2 == 0 = n : chain (n `div` 2) | otherwise = n : chain (3 * n + 1) chainLength n = (n,length (chain n)) array = ...

Integrating Haskell in non-functional projects

I have looking to Haskell questions in SO, and I recovering my university notes on funtional programming as a hobby. But I've always wondered how could something done in Haskell get outside Hugs interpreter and integrate with a C#, C++ or Java project. Has anybody done that? How? ...

Iterating with respect to two variables in haskell

OK, continuing with my solving of the problems on project Euler, I am still beginning to learn Haskell and programming in general. I need to find the lowest number divisible by the numbers 1:20 So I started with: divides :: Int -> Int -> Bool divides d n = rem n d == 0 divise n a | divides n a == 0 = n : divise n (a+1) | other...

install haskell cabal w/o manual dependency resolution

I see there's a nice package system called Cabal that handles dependency resolution. So I'm trying to install that so I can get it to install the Haskell OpenGL modules for me. However, Cabal itself has lots of dependencies. Is there a way to install Cabal without manually resolving all of its dependencies? I tried running the bootstrap,...

Is Haskell mature enough for web applications?

Seems that there are not much work done on Haskell for web. People uses it as a learning tool for functional programming more than business. Has anyone developed and deployed web application on Haskell, yet? Please, share the links. The next session comments might change my mind and plan something else which could b...

What is the ecosystem for Haskell web development?

Inspired by this question and a recent affair, I'm wondering what's involved with Haskell web development. Are there any Haskell web frameworks or template engines? How would hosting a Haskell site work, are there suitable web servers? Is Haskell too complex for the usual rapid development and prototyping based workflow often used ...