haskell

Haskell Convert List to List of Tuples

Hello, i have a list like this ["peter","1000","michell","2000","kelly","3000"] and i would like to convert to [("peter",1000),("michell", 2000),("kelly",3000)] Please help. Thanks. ...

Haskell IO Passes to Another Function

This question here is related to http://stackoverflow.com/questions/3066956/haskell-input-return-tuple I wonder how we can passes the input from monad IO to another function in order to do some computation. Actually what i want is something like -- First Example test = savefile investinput -- Second Example maxinvest :: a maxinvest...

How do I use multiple where clauses in GHCi?

I'm playing around with GHCi for the first time, and I'm having some trouble writing multi-line functions. My code is as follows: Prelude> :{ Prelude| let diffSquares lst = abs $ squareOfSums lst - sumOfSquares lst Prelude| where Prelude| squareOfSums lst = (fst (sumsAndSquares lst))^2 Prelude| sumOfSquares lst = snd (sumsAndS...

Regex capturing named groups in a language that doesn't support them using a meta regex?

I am using Haskell and I don't seem to find a REGEX package that supports Named Groups so I have to implement it somehow myself. basically a user of my api would use some regex with named groups to get back captured groups in a map so /(?P<name>[a-z]*)/hhhh/(?P<surname>[a-z]*)/jjj on /foo/hhhh/bar/jjj would give [("name","foo"),("s...

What does the `forall` keyword in Haskell/GHC do?

I'm beginning to understand how the forall keyword is used in so-called "existential types" like this: data ShowBox = forall s. Show s => SB s This is only a subset, however, of how forall is used and I simply cannot wrap my mind around its use in things like this: runST :: forall a. (forall s. ST s a) -> a Or explaining why these ...

How do I silence Network.Browser.browse's logs to stdout?

I'm using Network.Browser 4000.0.9 to retrieve a web page: import Network.Browser import Network.HTTP main = do (uri, response) <- browse $ do setAllowRedirects True setDebugLog Nothing request $ getRequest "http://www.google.com/robots.txt" putStrLn "done" Despite setDebugLog Nothing this spews all of thi...

Haskell SDL on OS X

SDL on OS X uses preprocessor tricks to overload main() with their own entry point, written in Objective C, which calls the user's main. These tricks make the lives of non-C SDL users (e.g: the Haskell bindings) very difficult. Is there a good reason for this? Why couldn't SDL do the objective-C Cocoa initialization in SDL_init? ...

Are Rank2Types/RankNTypes practical without polytype variables?

Since type variables cannot hold poly-types, it seems that with Rank*Types we cannot re-use existing functions because of their monotype restriction. For example, we cannot use the function (.) when the intermediate type is a polytype. We are forced to re-implement (.) at the spot. This is of course trivial for (.) but a problem for mor...

Choosing a Haskell parser

There are many open sourced parser implementations available to us in Haskell. Parsec seems to be the standard for text parsing and attoparsec seems to be a popular choice for binary parsing but I don't know much beyond that. Is there a particular decision tree that you follow for choosing a parser implementation? Have you learned anythi...

haskell import problem

I have a module "Dictionary", declared in a file "Dictionary.hs". in the same directory i have a file "Def.hs" which imports Dictionary here's the error i get ... /edsl/Def.hs:4:7: Could not find module `Dictionary': locations searched: Dictionary.hs Dictionary.lhs ... /edsl/Dictionary.hs is there. it's perm...

Large-scale design in Haskell?

Dear all, What is a good way to design/structure large functional programs, especially in Haskell? I've been through a bunch of the tutorials (Write Yourself a Scheme being my favorite, with Real World Haskell a close second) - but most of the programs are relatively small, and single-purpose. Additionally, I don't consider some of th...

HTTP POST contents in Haskell

I'm trying to post some data to a server in Haskell and the server side is coming up empty. I'm using the Network.HTTP library for the request. module Main (main) where import Network.URI (URI (..), parseURI, uriScheme, uriPath, uriQuery, uriFragment) import Network.HTTP import Network.TCP as TCP main = do conn <- TCP.openSt...

Do you know a Haskell package for dirent.h on Windows?

Hi, Do you know a Haskell package for dirent.h on Windows? There is similar set of functions in system.posix but those functions are not implemented on Windows. I wonder if there is similar somewhere else. Thanks. ...

Pattern matching in a let expression

How do you extract a value from a variable of an unknown constructor? For instance, I would like to negate the value in an Either if was constructed as a Right: let Right x = getValue in Right (negate x) This code successfully binds Right's value (an Int in this case) to x. This works, but what if getValue returns a Left instead? Is...

Orphaned instances in Haskell

When compiling my Haskell application with the -Wall option, GHC complains about orphaned instances, for example: Publisher.hs:45:9: Warning: orphan instance: instance ToSElem Result The type class ToSElem is not mine, it's defined by HStringTemplate. Now I know how to fix this (move the instance declaration into the module where...

In Haskell looking for a package that allows to consume a web response body as a stream

from RWH http://book.realworldhaskell.org/read/extended-example-web-client-programming.html The HTTP library used here does not read the HTTP result lazily. As a result, it can result in the consumption of a large amount of RAM when downloading large files such as podcasts. Other libraries are available that do not have this limitati...

foldl versus foldr behavior with infinite lists

The code for the myAny function in this question uses foldr. It stops processing an infinite list when the predicate is satisfied. I rewrote it using foldl: myAny :: (a -> Bool) -> [a] -> Bool myAny p list = foldl step False list where step acc item = p item || acc (Note that the arguments to the step function are correctly ...

Haskell List of Tuple Search

Hello to all, i have a list of tuple like this [("username", 123), ("df", 54), ("as",2 34)] I need to search the value based on username. I have using lookup but i need to change the value of the integer and write back to file. My logic of this is to delete the tuple and insert another new tuple value rather than change it. Any idea...

Regular expressions versus lexical analyzers in Haskell

I'm getting started with Haskell and I'm trying to use the Alex tool to create regular expressions and I'm a little bit lost; my first inconvenience was the compile part. How I have to do to compile a file with Alex?. Then, I think that I have to import into my code the modules that alex generates, but not sure. If someone can help me, I...

Using haskell read and typeclasses - ambiguous type variable error

Hi all, I have an ambiguous type variable error on the definition of "trial" below, I am wondering if there is anything that can be done to make this situation work? I want to really just deal with instances and not explicit data types (such as the MO1, MO2 included below). module Tc102 where class (Show a, Read a) => MyObj a where ...