4
голосов
2ответов
3536 просмотров

How do I get Cabal to bypass my Windows proxy settings?

When retrieving packages with Cabal, I frequently get errors with this message: user error (Codec.Compression.Zlib: premature end of compressed stream) It looks like Cabal is using my Windows Networking proxy settings (for Privoxy). From digging around Google, Cabal or its libraries appe...

0
голосов
1ответов
576 просмотров

Optimisations for a series of functions in Haskell

I am trying to do problem 254 in project euler and arrived at this set of functions and refactor in Haskell: f n = sum $ map fac (decToList n) sf n = sum $ decToList (f n) g i = head [ n | n <- [1..], sf n == i] sg i = sum $ decToList (g i) answer = sum [ sg i | i <- [1 .. 150] ] Whe...

1
голосов
1ответов
968 просмотров

Haskell Conditionals

I'm having some difficulty integrating && within Guards eg: something :: Char -> Int something k | ord k >= 77 && ord k <= 98 = 8 | otherwise = 88 How the heck can i achieve the above without setting off an error? Cheers.

6
голосов
4ответов
946 просмотров

How is (==) defined in Haskell?

I'm writing a small functional programming language in Haskell, but I can't find a definition of how (==) is implemented, as this seems to be quite tricky?

6
голосов
4ответов
432 просмотров

Comprehensions in Python and Javascript are only very basic?

Looking at comprehensions in Python and Javascript, so far I can't see some of the main features that I consider most powerful in comprehensions in languages like Haskell. Do they allow things like multiple generators? Or are they just a basic map-filter form? If they don't allow multiple ge...

2
голосов
3ответов
2475 просмотров

Haskell base-4.x package installation

when I try to install this package http://hackage.haskell.org/package/base-4.1.0.0 by running: runhaskell Setup configure I am getting this error: attempting to use module `System.IO' (System/IO.hs) which is not loaded Not in scope: `System.IO.stderr' Not in scope: `System.IO.stdin' ghc-6.8...

0
голосов
2ответов
696 просмотров

Issue with recursion writing a tiny parser in Haskell. Check variables

I'm still working on a tiny parser for a tiny language defined in a task at school. The parser that generates an AST(Abstract syntax tree) is working. What I want is to check the defined variables, they must be bounded by the let expression. First the method that is defined in the task(suggestion...

14
голосов
3ответов
2756 просмотров

Return specific type within Haskell

I have a pretty general question about Haskell's type system. I'm trying to become familiar with it, and I have the following function: getN :: Num a => a getN = 5.0 :: Double When I try to compile this, I get the following error: Couldn't match expected type `a' against inferred type `Dou...

2
голосов
4ответов
722 просмотров

Why does Haskell interpret my Num type as an Enum?

I'm trying to compile the following function in Haskell to mimic differentiation of a polynomial whose constants are specified in a numerical list: diff :: (Num a) => [a] -> [a] diff [] = error "Polynomial unspecified" diff coeff = zipWith (*) (tail coeff) [0..] Haskell refuses to compil...

0
голосов
2ответов
112 просмотров

Guard is skipped when it should not be

I have the following snippet of code module Main where main :: IO() main = do ne <- getLine c <- getLine putStrLn $ show $ foo c (words ne) foo :: String -> [String] -> Integer foo c (n:e:_) = foo' (read c::Integer) (read e::Integer) (read n::Integer) [2..] where foo...

2
голосов
2ответов
1646 просмотров

Why is Haskell throwing a 'cannot construct infinite type' error?

I wrote the following code in Haskell to compute the dot product of two vectors, but cannot compile it due to the following error: cannot construct infinite type: a = [a] When generalising the type(s) for dot' dot :: (Num a) => [a] -> [a] -> a [] `dot` [] = 0 [email protected][xi,xs] `dot` [email protected][yi,ys]...

3
голосов
1ответов
681 просмотров

Haskell recursive problem, tiny parser. Negation of Expr and let expressions

data Expr = Var Char | Tall Int | Sum Expr Expr | Mult Expr Expr | Neg Expr | Let Expr Expr Expr deriving(Eq, Show) parseExpr :: String -> (Expr, String) parseExpr ('*':'(':s) = (Mult x y, s'') where (x,',':s') = parseExpr s (y,')':s'') = parseExpr s' parseExpr ('+':'(':s...

2
голосов
3ответов
2846 просмотров

Concatenating a list of numbers into one integer in haskell

I am doing yet another Project Euler problem - Problem 38. I have this function which returns a list of numbers but what I need is that list of numbers to be one number. It calculates the concatenated product of an integer. f (a,b) = a*b conProInt x n = map f (zip (replicate n x) ([1..n])) pro...

6
голосов
4ответов
1870 просмотров

Computing π to "infinite" binary precision in C#

So far it looks like Fabrice Bellard's base 2 equation is the way to go Ironically this will require a BigReal type; do we have this for .Net? .Net 4.0 has BigInteger. Anyone have a Haskell version?

1
голосов
7ответов
739 просмотров

How to get Haskell syntax highlighting on PHP blog

I'm making a blog in PHP and I'd really like to have syntax highlighting on Haskell code. Are there any tools for that out there? I've found hscolour but I don't know if it's possible to integrate it in PHP. I'm using CakePHP if that makes a difference. Thanks.

1
голосов
4ответов
703 просмотров

How to programmatically retrieve GHC package information?

More specifically, given an arbritary package name I need to retrieve the same library-dirs field that can be obtained with the ghc-pkg describe command from inside a running Haskell program.

0
голосов
1ответов
724 просмотров

Haskell recursive problem, tiny parser. A few things

data Expr = Var Char | Tall Int | Sum Expr Expr | Mult Expr Expr | Neg Expr | Let Expr Expr Expr deriving(Eq, Show) That is the datatype for Expr, I have a few questions. I'm suppose to parse expressions like *(Expr,Expr) as shown in the datatype definition. However I do have some problem...

27
голосов
3ответов
4899 просмотров

Writing a time function in Haskell

I’m new to Haskell and I’d like to be able to time the runtime of a given function call or snippet of code. In Clojure I can use ‘time’: user=> (time (apply * (range 2 10000))) "Elapsed time: 289.795 msecs" 2846259680917054518906413212119868890148051... In Scala, I can define the function ...

1
голосов
2ответов
411 просмотров

Pattern match data types and their nested name in Haskell

I have: data Color = Blue | Green | Red | White | Yellow deriving (Eq,Ord) And then data Term = Color | ... data Bag = Bag { color :: Color ... } Now I want to be able to pattern match to make sure that the term given is a Color and if so check it's "value" (Blue/Green...). Something like t...

6
голосов
2ответов
1744 просмотров

How do I do python-style indent/dedent tokens with alex/haskell?

I'm writing a lexer for a small language in Alex with Haskell. The language is specified to have pythonesque significant indentation, with an INDENT token or a DEDENT token emitted whenever the indentation level changes. In a traditional imperative language like C, you'd keep a global in the le...

1
голосов
3ответов
837 просмотров

Haskell compilation problem

I have a problem compiling Haskell programs, that import the Text.Regex.Posix module. I have tried to isolate the problem in a small test program: module Main () where import Text.Regex.Posix ((=~)) main = return () Running the interpreter works fine: /regex-test$ runghc Main.hs /regex-test...

5
голосов
5ответов
848 просмотров

Can I write components in Haskell to be used on a Django site?

I have an idea for a web service, but am very new to web programming. Django looks great and like something I can pick up quickly. I have a lot of experience in Haskell (and very little in python) and would like to be able to start writing some of the backend non-web-related things in my favorite...

4
голосов
2ответов
481 просмотров

Is there a way to optimise this program in Haskell?

I am doing project euler question 224. And whipped up this list comprehension in Haskell: prob39 = length [ d | d <- [1..75000000], c <- [1..37500000], b <-[1..c], a <- [1..b], a+b+c == d, a^2 + b^2 == (c^2 -1)] I compiled it with GHC and it has been running with above average kern...

29
голосов
5ответов
48122 просмотров

Finding index of element in a list in Haskell?

I have a function in Haskell which finds the maximum value of an exponentiation from a list: prob99 = maximum $ map (\xs -> (head xs)^(head (tail xs))) numbers What I need to find is the location of this maximum value in the resultant list. How would I go about this? Edit: I found a soluti...

2
голосов
3ответов
1772 просмотров

Problem using map with a list of lists in Haskell

I am using Haskell to solve problem 99 in euler project, where I must find the maximum result from a list of base exponent pairs. I came up with this: prob99 = maximum $ map ((fst)^(snd)) numbers Where the numbers are in the form: numbers = [[519432,525806],[632382,518061],[78864,613712].. ...

1
голосов
3ответов
286 просмотров

Something like mapM, but for arrays? (like arrayMap, but mapping an impure function)

I see that I can map a function over mutable arrays with mapArray, but there doesn't seem to be something like mapM (and mapM_). mapArray won't let me print its elements, for example: import Data.Array.Storable arr <- newArray (1,10) 42 :: IO -- answer to Life, Universe and Everything x &lt...

14
голосов
4ответов
3406 просмотров

Call a Haskell function in .NET

I want to use a Haskell function with the following type :: string -> string from a C# program. I want to use hs-dotnet to bridge both worlds. The author claim that it's possible, but provide no sample of this case. The only samples provided are the one to use .NET from Haskell. Is there a s...

3
голосов
4ответов
876 просмотров

Detecting cyclic behaviour in Haskell

I am doing yet another projecteuler question in Haskell, where I must find if the sum of the factorials of each digit in a number is equal to the original number. If not repeat the process until the original number is reached. The next part is to find the number of starting numbers below 1 millio...

9
голосов
3ответов
4086 просмотров

How to produce a local datetime string in Haskell?

I want to produce the local time and date in string form, such as, for example: "2009-09-28-00-44-36.896200000000"

2
голосов
4ответов
836 просмотров

Haskell function taking a long time to process

I am doing question 12 of project euler where I must find the first triangle number with 501 divisors. So I whipped up this with Haskell: divS n = [ x | x <- [1..(n)], n `rem` x == 0 ] tri n = (n* (n+1)) `div` 2 divL n = length (divS (tri n)) answer = [ x | x <- [100..] , 501 == (divL x)]...