haskell

Haskell Parsec compile error

I've installed Haskell via the pre built installer v6.8.2. When trying to compile this sample file with GHC module Main where import Text.ParserCombinators.Parsec import System.Environment main :: IO () main = do args <- getArgs putStrLn ("Hello") I get the following error: D:\src\Haskell>ghc -o read read.hs ghc -o read r...

Inheritence to extend a data structure in Haskell

A C++ programmer trying to learn Haskell here. Please excuse this probably easy question. I want to translate a program that represents 3D shapes. In C++ I have something like: class Shape { public: std::string name; Vector3d position; }; class Sphere : public Shape { public: float radius; }; class Prism : public Shape { publ...

Anyone ever flip (<$>)

I found defining the following (%) = flip fmap I can write code like the following: readFile "/etc/passwd" % lines % filter (not . null) to me it makes more sense then the alternative filter (not . null) <$> lines <$> readFile "/etc/passwd" Obviously its just a matter of order, does anyone else do this? is there a valid reason ...

Generating a list of lists of Int with QuickCheck

I'm working through Real World Haskell one of the exercises of chapter 4 is to implement an foldr based version of concat. I thought this would be a great candidate for testing with QuickCheck since there is an existing implementation to validate my results. This however requires me to define an instance of the Arbitrary typeclass that c...

Haskell compiler error: not in scope

I am trying to learn haskell by writing a simple file copy util: main = do putStr "Source: " srcPath <- getLine putStr "Destination: " destPath <- getLine putStrLn ("Copying from " ++ srcPath ++ " to " ++ destPath ++ "...") contents <- readFile srcPath writeFile destPath conten...

Pros And Cons Of Haskell

Hello, I've learned much languages, but now I want to choose one, but the language that I most liked was Haskell, it is like a interpreted language, but is a compiled. Then I want to know the pros and cons of this powerfull language(just to make the correct choice). ...

Is Haskell Embeddable?

I'm wanting to know if it's possible to develop applications in or on Haskell to Windows Mobile, also if there is any version of hugs or ghci for Windows Mobile. Thanks. ...

Haskell Noob question: What's wrong with my append function?

Hi guys, I'm trying to write a Haskell append function... Here's what I have: myappend :: [a] -> [a] -> [a] myappend [] x = x myappend [x:xs] y = x : myappend xs y But it's giving me an error: Occurs check: cannot construct the infinite type: a = [a] When generalising the type(s) for `myappend' So, obviously there's something...

Map function for custom n-ary tree

I'm trying to get a mapping function like this working for an n-ary tree, but am struggling. data NTree a = Leaf a | Node a [NTree a] ntreeMap :: (a -> b) -> NTree a -> NTree b ntreeMap f (Leaf x) = Leaf (f x) ntreeMap f (Node y t) = Node (ntreeMap f y) (ntreeMap f t) gives me Type error in application *** Expression : ntreeM...

What does the : infix operator do in Haskell?

I'm reading A Gentle Introduction to Haskell (which is not so gentle) and it repeatedly uses the : operator without directly explaining what it does. So, what exactly does it do? ...

Replacing an element in a n-ary tree

I'm pretty new to Haskell and still have some problems getting my head around functional programming. With that said: I have a custom n-ary tree datatype data Tree = Empty | Leaf String | Node String [Tree] I'm trying to write a function to replace an element in a tree, i.e. replaceInTree :: String -> String -> Tree -> Maybe Tree ...

Differences Between Hugs, Yhc and GHCi

There are differences between Hugs, Yhc and GHCi? If there are differences, What are they? ...

Is there a way to list the functions in a module in GHCI?

I find it handy in Python or Common Lisp that you list a libraries contents at runtime. Does Haskell have the same thing, in particular from a GHCI prompt? ...

How to split up a file into modules in Haskell?

Hi, I'm having an issue with the syntax for modules. Basically I'm trying to split my code into two seperate files, one for the object I'm creating (AST), and one for all of my functions. --main.hs data AST = Add (AST) (AST)| Sub (AST) (AST)| Mult (AST) (AST)| Ident Char| ...

Cabal not installing dependencies when needing profiling libraries?

I want to compile my program with profiling, so I run: $ cabal configure --enable-executable-profiling ... $ cabal build ... Could not find module 'Graphics.UI.GLUT': Perhaps you havent installed the profiling libraries for package 'GLUT-2.2.2.0'? ... $ # indeed I have not installed the prof libs for GLUT, so.. $ cabal install...

Replacing characters with numbers in Haskell

Hi, I have started to do the questions on project euler regarding lists of names which need to be replaced with their corresponding position in the alphabet. In question 22 I need to replace, the letters with numbers: names = ["MARY","PATRICIA","LINDA".... replace = ?????? char2num a = map replace a score (a,b) = a * (sum $ map char2num...

haskell, chaining filters

to write "map f (map g xs)" as a single call to map you could write example xs = map (f.g) xs but how would you write "filter p (filter q xs)" as a single call to filter? the dot operator doesnt seem to work for filter as it does for maps. guessing you'd use something else for predicates? ...

Closest equivalent to subprocess.communicate in Haskell

I want to do a popen() / python's subprocess.communicate from Haskell - start a program, give it stdin, and get its stdout/stderr. What's the most direct / Haskellish way to do this? ...

haskell grouping problem

group :: Ord a => [(a, [b])] -> [(a, [b])] I want to look up all pairs that have the same fst, and merge them, by appending all the list of bs together where they have the same a and discarding the unnessecary pair and so on... I got as far as: group ((s, ls):(s', ls'):ps) = if s == s' then group ((s, ls++ls'):ps) else...

Is it possible to use unary function instead of binary in `flip`?

The type of the Prelude function flip is: flip :: (a -> b -> c) -> b -> a -> c I.e., it takes one binary function and two arguments. The type of the Prelude function id is: id :: a -> a But the type of flip id is: flip id :: a -> (a -> b) -> b How is it possible to apply flip to id when id is a unary function and flip requires ...