haskell

Are there any purely functional Schemes or Lisps?

I've played around with a few functional programming languages and really enjoy the s-expr syntax used by Lisps (Scheme in particular). I also see the advantages of working in a purely functional language. Therefore: Are there any purely functional Schemes (or Lisps in general)? ...

Which is your favorite "hidden gem" package on Hackage?

There are a lot of packages on Hackage, some well known (such as HUnit) and some less known (such as AspectAG). I'm wondering which package you think is a hidden gem that deserves more users. Maybe a useful data structure, helpers for monads, networking, test, ...? Which is your favorite "hidden gem" package on Hackage? ...

How can my-program.hs get its version number from my-program.cabal at build time?

I would like my cabalised program to have a --version switch. I would like it to report the same version as is present in the .cabal file. If I have to update the version number separately in my Haskell source code as well as in the .cabal file, I will eventually get them out of sync. So, how can my program, while being compiled under...

haskell network io hgetline

I want to read all the data on a handle, and then block waiting for more data. listen1 stops when there is a '\n' character in the stream. listen2 works and could be made completely general by imitating the code for hGetNonBlocking. What is the best way to do this? import qualified Data.ByteString as B loop = sequence_ . repeat lis...

Cabal and zlib on OS X

When I run "cabal update" on my Mac (Snow Leopard, Intel), I get: % cabal update Downloading the latest package list from hackage.haskell.org cabal: Codec.Compression.Zlib: incompatible zlib version Anyone else seeing this? Reinstalling the Haskell Platform hasn't helped. I'm unable to install or update Cabal packages at the moment, ...

Haskell - how to write array to file?

I am trying: saveArr = do outh <- openFile "test.txt" WriteMode hPutStrLn outh [1,2,3] hClose outh but it doesn't works... output: No instance for (Num Char) arising from the literal `1' EDIT OK hPrint works with ints but what about float number in array? [1.0, 2.0, 3.0]? ...

Type signature "Maybe a" doesn't like "Just [Event]"

I'm still learning Haskell and need help with the type inference please! Using packages SDL and Yampa I get the following type signature from FRP.Yampa.reactimate: (Bool -> IO (DTime, Maybe a)) and I want to use it for: myInput :: Bool -> IO (DTime, Maybe [SDL.Event]) myInput isBlocking = do event <- SDL.pollEvent return (1,...

Using items in a list as arguments

Suppose I have a function with the following type signature: g :: a -> a -> a -> b I also have a list of as—let's call it xs—that I know will contain at least three items. I'd like to apply g to the first three items of xs. I know I could define a combinator like the following: ($$$) :: (a -> a -> a -> b) -> [a] -> b f $$$ (x:y:z:_) ...

Infinite loop in haskell? (newbie)

I'm just learning Haskell. I thought this would produce a factorial function... (within ghci) Prelude> let ft 0 = 1 Prelude> let ft n = n * ft (n - 1) Prelude> ft 5 (hangs indefinitely, until ^C). Can someone point me in the right direction? Thanks! ...

In Haskell, what does it mean if a binding "shadows an existing binding"?

I'm getting a warning from GHC when I compile: Warning: This binding for 'pats' shadows an existing binding in the definition of 'match_ignore_ancs' Here's the function: match_ignore_ancs (TextPat _ c) (Text t) = c t match_ignore_ancs (TextPat _ _) (Element _ _ _) = False match_ignore_ancs (ElemPat _ _ _) (Text t) = False match_ig...

Confusion regarding laziness

I have a function myLength = foldl (\ x _ -> x + 1) 0 which fails with stack overflow with input around 10^6 elements (myLength [1..1000000] fails). I believe that is due to the thunk build up since when I replace foldl with foldl', it works. So far so good. But now I have another function to reverse a list : myReverse = foldl (\ ...

Want to add a functional language to my toolchest. Haskell or Erlang?

I've been an OO/procedural guy my whole career except in school where I did a lot of logic programming (Prolog). I work on an amazing variety of projects (freelancer) and so I don't want the tools I know and understand to hold me back from using the right tool for the job. I've decided I should know a functional programming language. I'...

Why is writing a compiler in a functional language easier?

Hello all, I've been thinking of this question very long, but really couldn't find the answer on Google as well a similar question on Stackoverflow. If there is a duplicate, I'm sorry for that. A lot of people seem to say that writing compilers and other language tools in functional languages such as OCaml and Haskell is much more effi...

Haskell mutability in compiled state?

I do not know much about Haskell, but from what I have read about the mutability of computations (e.g: functions returning functions, complex monads and functions, etc.) it seems like you can do a lot of meta-programming, even at runtime. How can Haskell, if everything like functions and monads are so complex, compile to machine code a...

Optimizing Haskell code

I'm trying to learn Haskell and after an article in reddit about Markov text chains, I decided to implement Markov text generation first in Python and now in Haskell. However I noticed that my python implementation is way faster than the Haskell version, even Haskell is compiled to native code. I am wondering what I should do to make the...

adding other files to haskell

Hello, Im writing app in haskell and I would like to export some functions and datatypes to other files and then be able to use them in my main file. How to do this ? thanks for help ...

How do I convert a list to a tuple in Haskell?

How can I best convert a list to a tuple in Haskell: [1,2,3,4,5,6] -> (1,2,3,4,5,6) ...

how to make Random in haskell in pure function

I want make a haskell function can pick out random number from a given list. there type are randomPick :: [a] -> a what should i do ? ...

Strange type-related error

I wrote following program: isPrime x = and [x `mod` i /= 0 | i <- [2 .. truncate (sqrt x)]] primes = filter isPrime [1 .. ] it should construct list of prime numbers. But I got this error: [1 of 1] Compiling Main ( 7/main.hs, interpreted ) 7/main.hs:3:16: Ambiguous type variable `a' in the constraints: `Floati...

How to write Haskell function to verify parentheses matching?

I need to write a function par :: String -> Bool to verify if a given string with parentheses is matching using stack module. Ex: par "(((()[()])))" = True par "((]())" = False Here's my stack module implementation: module Stack (Stack, push, pop, top, empty, isEmpty) where data Stack a = Stk [a] ...