haskell

When should I use record syntax for data declarations in Haskell?

Record syntax seems extremely convenient compared to having to write your own accessor functions. I've never seen anyone give any guidelines as to when it's best to use record syntax over normal data declaration syntax, so I'll just ask here. ...

Casting in Haskell

a) I need to cast from String to int in haskell. I have a function that gets the third word in a sentence as a string, but my third word in all my sentences are numbers (int), how can I cast from string to int so then I can use the number afterwards to do operations like add or mult? getThirdWord :: String -> String getThirdWord = head ...

If you can't change a variable's value in Haskell, how do you create data structures?

As per the title. I have the following code which creates a binary search tree, but if I want it created and changed dynamically with user input, how would I do that if I can't change the value of a variable in haskell?!? find :: (Ord a) => Node a -> a -> Bool find (Node val left right) s | s == val = True | s < val = find le...

Haskell execution sequence

Hi can anybody help me understand this code solve s | s == 0 = Nothing | s == 1 = Just 1 | otherwise = check [solve (s-(x*2)) | x <- [1..9]] check x = case x of [] -> Nothing (Nothing:xs) -> check xs (x:xs) -> x why this gives stack over flow when i tried to...

It's a good idea use ruby for socket programming?

My language of choice is Ruby, but I know because of twitter that Ruby can't handle a lot of requests. It is a good idea using it for socket development? or Should I use a functional language like erlang or haskell or scala like twitter developers did? ...

Convert Python to Haskell / Lambda calculus

What is the Python code in Haskell and Lambda calculus? def f1(): x = 77 def f2(): print x f2 f1 My attempt in lambda calculus \x. 77 (\x.x) ...

What are the differences and similarities of Scala and Haskell type systems?

How to explain Scala's type system to a Haskell expert? What examples show Scala's advantages? How to explain Haskell's type system to an advanced Scala practitioner? What can be done in Haskell that can't be done in Scala? ...

import List in haskell

I'm trying to work with lists in Visual Haskell Studio, but it doesn't recognize import Sytem.List neither does it recognize import List. How can I use simple list functios in VHS? Urgent! Thank you so much in advance!!! ...

List comprehension won't give correct result in Haskell

Hi I am doing project euler question 136, and came up with the following to test the example given: module Main where import Data.List unsum x y z n = (y > 0) && (z > 0) && (((x*x) - (y*y)- (z*z)) == n) && ((x - y) == (y - z)) answer = snub $ takeWhile (<100) [n|x<-[1..],d<-[1..x`div`2],n<-[x..100],y<-[x-d],z<-[y-d], unsum x y z n ] ...

Using the Github Gist API from Haskell

First of all, I've never really used APIs before, and I've never used the HTTP library in Haskell. I'm not sure what I'm doing wrong here, so maybe somebody who knows can help. I'm using what I can read of this: http://github.com/defunkt/gist/blob/master/gist.rb, namely the write method, to write this: req = postRequest "http://gist.gi...

Lifting class instance in Haskell

Is there a way to "lift" a class instance in Haskell easily? I've been frequently needing to create, e.g., Num instances for some classes that are just "lifting" the Num structure through the type constructor like this: data SomeType a = SomeCons a instance (Num a)=>Num SomeCons a where (SomeCons x) + (SomeCons y) = SomeCons (x+y)...

Haskell dividing num

I'm having an issue I want to learn more about, and how to avoid. I've got this code len :: (Num r ) => [a] -> r len [] = 0 len xs = 1 + len ( tail xs ) avg :: (Num t) => [t] -> Double avg xs = ( sum xs ) / ( len xs ) Which renders the following error len.hs:6:9: Couldn't match expected type `Double' against inferred type `t' ...

Haskell question about function

Working out of RWH, Chapter 3 question 5 requests I create a function to test for the existence of a paldindrome. I wrote this, but it doesn't work pCheck :: (Eq a) => [a] -> Bool; pCheck a = take n a == ( take n $ reverse a ) where n = floor ( length a / 2 ) I get this error when I try to run it: No instance for (RealFrac Int) ...

Haskell : ++ difference

I m sorry for a question like this. But i m not too sure about the difference of : and ++ operator in haskell. x:y:[] = [x,y] also [x] ++ [y] = [x,y] as for the reverse function which arose this question for me, reverse ::[a]->[a] reverse [] = [] reverse (x:xs) = reverse(xs)++[x] why doenst the following work? reversex ::[Int]...

XML alternative of Text.JSON.Generic for Haskell

Is there any XML-(de)serializer for Haskell using Data/Typeable with functions similar to toXml :: Data d => d -> XmlValue fromXml :: Data d => String -> Result d in the spirit of Text.JSON.Generic? ...

Haskell scoping in nested function definitions using where

I have a problem with Haskell's scoping in where definitions. When I have the following function f, where I want to pass the x to the locally defined function f1 without explicitely using it as a parameter, I get an error saying that the type of x is incompatible with the one in the output of f1, although it should be the same: f :: Eq...

"cannot do signed 4 byte relocation" on compile

I'm going through Real world Haskell, and got to the example: -- file: ch04/InteractWith.hs -- Save this in a source file, e.g. Interact.hs import System.Environment (getArgs) interactWith function inputFile outputFile = do input <- readFile inputFile writeFile outputFile (function input) main = mainWith myFunction where mainWi...

Haskell List Comprehension

I get the error "Not in scope: x" when doing as follows... blanks :: Sudoku -> [Pos] blanks (Sudoku su) = [ fst x | x <- posSud | isBlank (snd x) ] where isBlank Nothing = True isBlank _ = False posSud = zip ixPos (concat su) ixPos = zip ixRows ixCols ixCols = concat (replicate 9 [0..8]) ixRows ...

How to customize the readline keybindings of ghci

I know ghci supports readline , and keybindings such as ^W and ^U work as expected. But I do wonder whether ghci support the customization of keybindings , just like the way bash deal with inputrc ? Thanks for any feedback. ...

Haskell typeclass

I have a Haskell typeclass question. I can't munge the syntax to get this (seemingly reasonable) program to compile under GHC. import Control.Concurrent.MVar blah1 :: [a] -> IO ([a]) blah1 = return blah2 :: [a] -> IO (MVar [a]) blah2 = newMVar class Blah b where blah :: [a] -> IO (b a) instance Blah [] where blah = blah1 -- BO...