ghc

Basics of Haskell compiling

I'm working on the 2nd Euler's problem, but for now I'm just trying to define the Fibonacci sequence. Currently, I have my Fib function defined as Fib 0 = 0 Fib 1 = 1 Fib x = Fib (x - 1) + Fib (x - 2) Because I want the program to depend on my keyboard input, I used main = do putStrLn "Enter desired Fibonacci index: " ...

No instance for (Floating Int)

I am learning Haskell. I have created function which returns multiplication table up to 'n' in base 'b'. Numbers are padded to 'w' digits. As the last step, I want to compute 'w' automatically. Why does this not compile? -- Number of digits needed for the multiplication table n*n in base 'base' nOfDg :: Int -> Int-> Int nOfDg n base = ...

What can be improved on my first haskell program?

Here is my first Haskell program. What parts would you write in a better way? -- Multiplication table -- Returns n*n multiplication table in base b import Text.Printf import Data.List import Data.Char -- Returns n*n multiplication table in base b mulTable :: Int -> Int -> String mulTable n b = foldl (++) (verticalHeader n b w) (map (...

Distributing a Haskell program as C source

Say I have a Haskell program or library that I'd like to make accessible to non-Haskellers, potentially C programmers. Can I compile it to C using GHC and then distribute this as a C source? If this is possible, can someone provide a minimal example? (e.g., a Makefile) Is it possible to use GHC to automatically determine what compile...

using oneOf in haskell, errors in compiling

Hi, I'm a complete newbie at Haskell. I'm trying to compile this Haskell file I've downloaded but it's giving me some errors. No instance for (Text.Parsec.Prim.Stream s m Char) arising from a use of 'letter' at Parse.lhs:649:26-31 Possible fix: add an instance declaration for (Text.Parsec.Prim.Stream s m Char) In the first argume...

Using Haskell to output a UTF-8-encoded ByteString

I'm going out of my mind trying to simply output UTF-8-encoded data to the console. I've managed to accomplish this using String, but now I'd like to do the same with ByteString. Is there a nice and fast way to do this? This is what I've got so far, and it's not working: import Prelude hiding (putStr) import Data.ByteString.Char8 (put...

Need a tutorial for using GHC to parse and typecheck Haskell

I'm working on a project for analyzing Haskell code. I decided to use GHC to parse the source and infer types rather than write my own code to do that. Right now, I'm slogging through the Haddock docs, but it's slow going. Does anyone know of a good tutorial? EDIT: To clarify, I'm not looking for something like hlint. I'm writing my...

Catching Control-C exception in GHC (Haskell)

I built a really simple read-eval-print-loop in Haskell that catches Control-C (UserInterrupt). However, whenever I compile and run this program, it always catches the first Control-C and always aborts on the second Control-C with exit code 130. It doesn't matter how many lines of input I give it before and between the two Control-Cs, ...

Evaluation of Haskell Statements/Expressions using GHC API

For a tool I'm writing ( http://hackage.haskell.org/package/explore ) I need a way to read haskell function definitions at run-time, apply them to values from my tool and retrieve the results of their application. Can anyone give me a very basic example using GHC (6.10.4 or 6.12.1) API? example function definition to be read from a fil...

Wrong IO actions order using putStr and getLine

I have a code : main = do putStr "Test input : " content <- getLine putStrLn content And when I run it (with runhaskell) or compile it (ghc 6.10.4) result is like this: asd Test input : asd I'm new to haskell and in my opinion printing should be first. Am I right? In code sample on http://learnyouahaskell.com/ which use...

CPP extension and multiline literals in Haskell

Is it possible to use CPP extension on Haskell code which contains multiline string literals? Are there other conditional compilation techniques for Haskell? For example, let's take this code: -- If the next line is uncommented, the program does not compile. -- {-# LANGUAGE CPP #-} msg = "Hello\ \ Wor\ \ld!" main = putStrLn msg ...

Using GHC, cabal with GMP installed in user-space

I have been trying to install Haskell Platform and cabal-install installed on Linux in user-space on a system that doesn't have the GNU Multi-Precision package (GMP) installed. I managed to get GHC-6.12.1 installed and ghci working by setting up LB_LIBRARY_PATH to point at the lib directory where I installed GMP, but then ran into probl...

Haskell: What's the type of this function?

mifun s = foldr op 0 s where op x r = head x + r Is there a way to make ghci tell me? ...

How are lists implemented in Haskell (GHC)?

I was just curious about some exact implementation details of lists in Haskell (GHC-specific answers are fine)--are they naive linked lists, or do they have any special optimizations? More specifically: Do length and (!!) (for instance) have to iterate through the list? If so, are their values cached in any way (i.e., if I call length...

What is the relationship between ghc-pkg and cabal?

With respect to how packages are created, installed and used in Haskell, what is the relationship between ghc-pkg and cabal? What are their roles - when would you use one, over the other, or use both? Are they complementary tools, competitive tools, or simply tools that do different jobs? ...

GHC 6.12 and MacPorts

I recently installed (from the binary installers) GHC 6.12 and the Haskell Platform 2010.1.0.1 on my Intel MacBook running OS X 10.5.8, and initially, everything worked fine. Edit: I had to install cabal, alex, and happy from source, but after that, everything did seem to work fine. However, I discovered that if I use cabal install to ...

Demangling typeclass functions in GHC profiler output

When profiling a Haskell program written in GHC, the names of typeclass functions are mangled in the .prof file to distinguish one instance's implementations of them from another. How can I demangle these names to find out which type's instance it is? For example, suppose I have the following program, where types Fast and Slow both imp...

Manipulating source packages from Hackage how to easy deploy to several windowsboxes?

Recently when I have found good sources packages for ghc 6.12/6.10 on Hackage I've been forced to do some minor or major changes to the cabal files to make those packages to work under windows. Besides to fork and merge my fixes with github, what seems to be the best way/ good enough practice to take these modified builds to a couple of ...

Is do-notation specific to "base:GHC.Base.Monad"?

The idea that the standard Monad class is flawed and that it should actually extend Functor or Pointed is floating around. I'm not necessarily claiming that it is the right thing to do, but suppose that one was trying to do it: import Prelude hiding (Monad(..)) class Functor m => Monad m where return :: a -> m a join :: m (m a...

Applying a function with multiple inputs using Map? (Haskell)

G'day guys, Trying currently to finish up a bit of homework I'm working on, and having an issue where I'm trying to apply map across a function that accepts multiple inputs. so in the case I'm using processList f (x:xs) = map accelerateList f xs x xs processList is given a floating value (f) and a List that it sorts into another List ...