haskell

Pattern matching string prefixes in Haskell

Let's say I want to make a special case for a function that matches strings that start with the character 'Z'. I could easily do it using pattern matching by doing something like the following: myfunc ('Z' : restOfString) = -- do something special myfunc s = -- do the default case here But what if I want to match strings with a longer...

Is there any benefit to porting the Haskell Edison API and Core to F#?

The Edison API and Core modules are the Haskell implementation of Purely Functional Data Structures Do the F# and native .Net data structures cover use cases in the Edison API and Core sufficiently? Would there be any benefit to trying to port the API and CORE Haskell modules to F#? ...

What is Haskell actually useful for?

I really hope nobody deems this question as closable because it's a pretty straight forward one. I Googled this question, but not much information was found that was concise and informative for me. For instance, if I start learning Haskell, what can I find myself using it for. What are some common uses for this language that I hear is ...

Explanations about the mechanics of a simple factorial function

I'm new to Haskell, so I'm both naive and curious. There is a definition of a factorial function: factorial n = product [1..n] I naively understand this as: make the product of every number between 1 and n. So, why does factorial 0 return 1 (which is the good result as far as my maths are not too rusted)? Thank you ...

Intermediate lists in Haskell

Hi I am doing Project Euler question 55 on Lychrel numbers where the aim is to find the number of Lychrel numbers below 10,000 within 50 iterations. I came up with this: revAdd n = (read $ reverse $ show n) + n lychrel n | length xs == 50 = error "False" | ((reverse $ show (revAdd n)) == (show (revAdd n))) = True | other...

Haskell & Oracle

I reviewed different means for connecting to oracle db from Haskell. I found one, ODBC. Ideally, I wish to use an oracle client to connect. Do you know any other way? Thank you. ...

Filtering list of tuples

New to Haskell and have a stumbling block. I'm trying to filter a list of tuples based on the first item. filter (==(x,_)) lis I get an illegal '_' error, but I'm not sure how I can get around it? ...

Laziness and tail recursion in Haskell, why is this crashing?

I have this fairly simple function to compute the mean of elements of a big list, using two accumulators to hold the sum so far and the count so far: mean = go 0 0 where go s l [] = s / fromIntegral l go s l (x:xs) = go (s+x) (l+1) xs main = do putStrLn (show (mean [0..10000000])) Now, in a strict language, this...

Finding if two numbers have the same digit and then remove them from in the original number in Haskell

Hi I am doing project euler question 33 and have divised a refactor to solve it but I can't think of how to remove the digit if it is the same across both x and y. I got this far: import Ratio import List p33 = [ (x%y) | y <- [10..99] , x <- [10..y], (x `rem` 10) /= 0 , (y `rem` 10) /= 0 , x /= y , (length $ nub $ concat $ map decToLis...

Some questions about monads in Haskell

I'm learning about monads and have a few questions. This is where I am right now. Please correct me where I am wrong. The >>= symbol is an infix operator. Infix operators are functions that take two arguments (left-hand side and right-hand side) and return a value. The >>= symbol is called the bind operator and has signature Monad m =...

Parallel "insertions" into a binary trie in Haskell

I have a list of n-bit "words" type BitWord = [Bool] and a trie which stores the word from the top to bottom: data Tree = Bs Tree Tree -- Bs (zero_bit) (one_bit) | X -- incomplete word | B -- final bit of word I have a function: seenPreviously :: BitWord -> Tree -> (Tree,Bool) The function steps through the ...

Can liftM differ from liftA?

According to the Typeclassopedia (among other sources), Applicative logically belongs between Monad and Pointed (and thus Functor) in the type class hierarchy, so we would ideally have something like this if the Haskell prelude were written today: class Functor f where fmap :: (a -> b) -> f a -> f b class Functor f => Pointed f whe...

What is MACID ?

I've recently found the HAppS and Happstack projects, and the latter notes that one of its missions is to "leverage use of MACID". What exactly is MACID ? ...

how to write numbers in lambda using ghci

Hi. I am new to Haskell, using Ghci. I have a function, called three, that I want to write as let three = \x->(\y->(x(x(x y)))) OK, this works, but when I try three (2+) 4 It does not work. Instead, I get some "cannot construct infinite type" error. Please help me. ...

Haskell IO Testing

I've been trying to figure out if there is already an accepted method for testing file io operations in Haskell, but I have yet to find any information that is useful for what I am trying to do. I'm writing a small library that performs various file system operations (recursively traverse a directory and return a list of all files; sync...

In Haskell, how do I recursively manipulate a tuple and preappend a character to the first element in the tuple?

The type of this function is function :: Num a => ([Char],a) -> ([Char],a) My input for this function would be something like function (".'*",0) and the function finds the first '.' or '*' and updates a, by adding 200 or 400 to a's value depending on which character was replaced first. Once something is changed, the rest of the charact...

How to use fromInteger in Haskell?

One way to calculate 2^8 in haskell is by writing product(replicate 8 2) When trying to create a function for this, defined as follows... power1 :: Integer → Integer → Integer power1 n k | k < 0 = error errorText power1 n 0 = 1 power1 n k = product(replicate k n) i get the following error: Couldn't match expected type 'Int' again...

Significant Whitespace in C# like Python or Haskell?

I'm wondering if any other C# developers would find it an improvement to have a complier directive for CSC to make whitespace significant ala Haskell or Python where the kinds of whitespace creates code blocks. While this would certainly be a massive departure from c-style languages, it seems to me that since C# is ultimately being com...

The practical Haskell tutorial for a programmer coming from the imperative universe

What would be the most practical online tutorial(s) for quickly getting up to speed with Haskell? I have a decent amount of programming experience with PHP, Java ja Javascript, so there is something to build on. I have checked out the Haskell official homepage @haskell.org but the materials there are a bit ..well.. a bit difficult to fo...

A Haskell function of type: IO String-> String

I wrote a bunch of code in Haskell to create an index of a text. The top function looks like this: index :: String -> [(String, [Integer])] index a = [...] Now I want to give this function a String read from a file: index readFile "input.txt" Which won't work because readFile is of type FilePath -> IO String. Couldn't match exp...