haskell

Haskell List Reversal Error

Hi guys, I'm writing a list reversal program for haskell. I've got the idea for the list reversal and that has lead to the following code: myreverse list1 | list1 == [] = list1 | otherwise = (myreverse(tail list1)):(head list1) Unfortunately the above code results in the following error: Occurs check: cannot construct the...

Do I need to understand how Haskell represents data to be able to write good Haskell programs?

I'm learning Haskell from a Java background. When I program Java, I feel like I have a strong understanding of how objects are laid out in memory and the consequences of this. For example I know exactly how java.lang.String and java.util.LinkedList work and therefore I know how I should use them. With Haskell I'm a bit lost. For exam...

Systems programming in haskell?

Hey guys, Ive been thinking...Is it possible to go very low level in functional languages like haskell?(like making a kernel or device driver).And will functional features (like monads) be fast and efficient there? Thanks in advance ...

Haskell or D for GUI desktop application?

I like haskell and many things connected with it as its type-engine, lot of packages at Hackage, nice community, active development etc. Otoh, I had experience that some people gave up on our planned project considering Haskell too complicated (monads, lot of jargon from academia...) to grok (coming from C++ background), so it might be ...

Why does laziness go well with referential transparency?

Hello. I was reading a Haskell tutorial (Learn You a Haskell) in which the author said that laziness goes well with referential transparency. After more reading and some searching, I still don't understand why. Note that I do understand what's great about referential transparency and laziness, but it's them together that's troubling me....

How does deriving work in Haskell?

ADTs in Haskell can automatically become instance of some typeclasses (like Show, Eq) by deriving from them. data Maybe a = Nothing | Just a deriving (Eq, Ord) My question is, how does this deriving work, i.e. how does Haskell know how to implement the functions of the derived typeclass for the deriving ADT? Also, why is derivi...

Is it possible to use the GHC API to modify a program while compiling it?

I want to test the implementation a compiler optimization by piggybacking into the GHC compilation process and altering its Core representation. The idea would be to have something like: runGhc (Just libdir) $ do ... c <- compileToCoreModule targetFile compileCoreToObj False (modify c) ... where modify takes the Core repre...

Print a list of lists of Integers with Haskell returned by CombinatoricsGeneration.combinations

Hello, I already searched the Web, I have Real World Haskell but I can't figure how to print a list of lists of Integers when that list is returned by combinatoricsGeneration.combinations. I found the module at http://www.polyomino.f2s.com/david/haskell/combinatorics.html The functions have no type signature, so Haskell has to infer ev...

pure functional using F#

Is it possible to force F# to behave like a pure functional language like Haskell? May be using some compiler directives? ps: since i come from a C/C++ background, I want to force myself to learn functional programming without learning haskell :) ...

A monad is just a monoid in the category of endofunctors, what's the problem?

Who first said A monad is just a monoid in the category of endofunctors, what's the problem? and on a less important note is this true and if so could you give an explanation(hopefully one that can be understood by someone who doesn't have much haskell experience). ...

Haskell Question on pattern matching

Hi everyone, I'm trying to write a function that takes in a list and returns true if it is in sorted order and false if not: So far what I have is: myordered [] = True myordered [x] = True myordered list1 | (head list1) <= (head (tail list1)) = myordered(tail list1) | otherwise = False Based on our ...

Optimizing a Haskell function to prevent stack overflows

I'm trying to create a function that recursively plays all possible games of tic-tac-toe using a genetic algorithm, and then returns a tuple of (wins,losses,ties). However, the function below always overflows the stack when called like this: scoreOne :: UnscoredPlayer -> [String] -> ScoredPlayer scoreOne player boards = ScoredPlayer (to...

How can monads make my job easier? Show me some cool piece of code.

I like reading snippets of code about concepts that I don't understand. Are there any snippets that show off monads in all their glory? More importantly how can I apply monads to make my job easier. I use jQuery heavily. That's one cool application of monads I know of. ...

Options for pure-number module namespace?

It seems a pure-number module namespace like module 2010.Foo where is not allowed. One not so pretty option would be module V2010.Foo where Can you suggest other options? ...

How to list directories faster?

I have a few situations where I need to list files recursively, but my implementations have been slow. I have a directory structure with 92784 files. find lists the files in less than 0.5 seconds, but my Haskell implementation is a lot slower. My first implementation took a bit over 9 seconds to complete, next version a bit over 5 secon...

Authentication for hackage downloads?

Is there any way to ensure authenticity of downloads from hackage? As far as I can see, there's nothing. No https for hackage, and neither (strong) checksums for tarballs, and neither are they signed. So: how can I verify the authenticity of downloads from hackage? ...

Haskell - I am too old for this...

I am always interested in learning new languages, a fact that keeps me on my toes and makes me (I believe) a better programmer. My attempts at conquering Haskell come and go - twice so far - and I decided it was time to try again. 3rd time's the charm, right? Nope. I re-read my old notes... and get disappointed :-( The problem that mad...

Funky haskell lazy list implicit recursion

In Haskell, you can build infinite lists due to laziness: Prelude> let g = 4 : g Prelude> g !! 0 4 Prelude> take 10 g [4,4,4,4,4,4,4,4,4,4] Now, what exactly goes on when I try to construct a list like this? Prelude> let f = f !! 10 : f Prelude> f !! 0 Interrupted. Prelude> take 10 f [Interrupted. Prelude> The Interrupted.s are me ...

Can a TextEncoding be converted to a String?

It is possible to convert a string to a TextEncoding using mkTextEncoding :: String -> IO TextEncoding Is there any way to do do the reverse? Or, given a TextEncoding, any way to find out any information about that encoding? There doesn't even seem to be an Eq instance for TextEncoding to allow comparing against the defined encoding...

Departmental restriction against unsafePerformIO

There has been some talk at work about making it a department-wide policy of prohibiting the use of unsafePerformIO and its ilk. Personally, I don't really mind as I've always maintained that if I found myself wanting to use it, it usually meant that I need to rethink my approach. Does this restriction sound reasonable? I seem to reme...