Trying to create a base class from which I can derive different types. What's wrong with the following?
class (Eq a) => MyClass a
data Alpha = Alpha
instance MyClass Alpha where
Alpha == Alpha = True
I get the error:
test.hs:5:10: `==' is not a (visible) method of class `MyClass'
Failed, modules loaded: none.
...
Hello all. Experimenting with existential types. Seems to be a great way to get some type flexibility.
I'm hitting a problem with unboxing an existential type after I've wrapped it up. My code as follows:
{-# LANGUAGE ExistentialQuantification #-}
class Eq a => Blurb a
data BlurbBox = forall a . Blurb a => BlurbBox a
data Greek = Al...
I'm considering to learn a functional programming language. I decided to build a medium-sized web application.
I narrowed down the choices to Haskell and Common Lisp.
Web application needs to interface to some relational database (MySQL, Firebird or Postgres) and has to run on Linux. Obviously, it has to interface well with web serve...
I have a haskell function that that calculates the size of the list of finite Ints. I need the output type to be an Integer because the value will actually be larger than the maximum bound of Int (the result will be -1 to be exact if the output type is an Int)
size :: a -> Integer
size a = (maxBound::Int) - (minBound::Int)
I underst...
This is a fairly vague and open ended question, but hopefully someone can still provide some insight.
I am using GTK (through Gtk2Hs with Haskell via GHC) and I am wondering if there is any general advice for handling events. I am used to keeping system components loosely coupled (from OO practice) and this extends to the event model. I...
I've been comparing for fun different languages for speed in execution of the following program:
for i from 1 to 1000000 sum the product i*(sqrt i)
One of my implementations (not the only one) is constructing a list [1..1000000] and then folding with a specific funtion.
The program works fine and fast in Haskell (even when using foldl ...
I am learning Haskell after years of OOP.
I am writing a dumb web spider with few functions and state.
I am not sure how to do it right in FP world.
In OOP world this spider could be designed like this (by usage):
Browser b = new Browser()
b.goto(“http://www.google.com/”)
String firstLink = b.getLinks()[0]
b.goto(firstLink)
print(b....
I'm trying to install Haskell (for the first time). Following the instructions on the website, I downloaded:
ghc-6.10.4-i386-unknown-linux-n.tar.bz2
haskell-platform-2009.2.0.2.tar.gz
I unpacked the ghc package, and installed it without problems. Then I unpacked haskell-platform and run the following:
./configure --prefix=/usr
mak...
i'm completely stumped on how to Write a function that, given a list of sets returns the sets split into sublists by size (and with the sublists ordered by the size of sets they contain).
sample input
*Main> allSets
[[1,2],[8],[1,4,7,8],[5],[1,4],[1],[2,3],[1,2,5,8],[3,4,6,7],[1,2,3,4],[4],[5,6,7,8],[3,4],[3],[2,3,5,6],[7],[6],[2]]
sam...
I have an interesting problem, well at least to me and I can't seem to figure out how to resolve it, so i'm hoping you can help.
instance (Finite a, Finite b) => Finite (Either a b) where
elems = combineLists [Left x | x <- elems] [Right x | x <-elems]
size ??? = (size a) + (size b)
I'm working on an assignment for a class a...
Is there a way to get line-number/traceback information in Haskell?
(like C's __LINE__ macro or Python's traceback.extract_stack())
That would be of use for me for writing Haskell program that generates C++ code, which would be notated with comments telling which Haskell line is responsible for which C++ line.
Haskell example:
LINE "...
If you search for skips lists implemented in Haskell, you won't find many. It is a probabilistic data structure needing a random number generator, meaning that any of these structures would need to run in the IO monad.
Are Haskell folks staying away from these data structures because it's not possible to implement them purely? How can H...
if i do any isUpper "asBsd", i'll get True.
here, the second element to any is a string.
but, if i do this:
any ("1" `isInfixOf`) ["qas","123","=-0"]
the second element to any is a list of strings.
how and why this difference between those 2 functions?
another example.
if i write filter isUpper "asdVdf" , i'll get "V".
here, the se...
Basically I'm modifying a parser to handle additional operators. Before my changes, one part of the parser looked like this:
parseExpRec e1 (op : ts) =
let (e2, ts') = parsePrimExp ts in
case op of
T_Plus -> parseExpRec (BinOpApp Plus e1 e2) ts'
T_Minus -> parseExpRec (BinOpApp Minus e1 e2) ts'
T_Times -...
I was reading on different sieving algorithms when I stumbled upon a kind of improved version of the Sieve of Eratosthenes called Euler's Sieve. According to Wikipedia there is an implementation of an slightly different version of the idea (called Turner's Sieve) in Haskell.
Now I am trying to understand what exactly the code snippet gi...
I am trying to extend a recursive-descent parser to handle new operators and make them associate correctly. Originally there were only four operators (+ - / *) and they all had the same precedence. The function I am looking at is the parseExpRec function:
parseExpRec :: Exp -> [Token] -> (Exp, [Token])
parseExpRec e [...
I'm looking for a tree-based dictionary data structure which is easy to implement in Haskell.
Do you have any experience with implementing AVL trees or RB trees? I'm also thinking about splay trees, but don't see how they could be implemented using immutable data.
...
Hi, I'm pretty new to Haskell and I'm trying to work out how to traverse a n-ary tree. As output I'm looking to get a list of Leaf values (as the branches have no value), so for testtree this would be: 4,5
My definition so far is:
data Tree a = Leaf a | Branch [Tree a] deriving (Show)
travTree :: Tree a -> [a]
travT...
I wrote something like this:
instance Functor (Either e) where
fmap _ (Left a) = Left a
fmap f (Right b) = Right (f b)
How do I do the same if I want fmap to change the value only if it's Left?
I mean, what syntax do I use to indicate that I use type Either _ b instead of Either a _?
...
I am pretty new to Haskell (still working on totally understanding monads). I have a problem where I have a tree like structure
type Tree = [DataA]
data DataA = DataA1 [DataB]
| DataA2 String
| DataA3 String [DataA]
deriving Show
data DataB = DataB1 [DataA]
| DataB2 String
...