haskell

Hiding constructors of data type

When importing some data type, it is necessary to put (..) for constructors to be imported. Is it possible to prevent exporting constructors of some data type, even when that data type is exported? ...

Complex structure translation with lazy evaluation

Some background: I am writing a generic high-level to low-level compiler. On the high-level side, it understands classes, methods, fields, virtual method calls, etc. and on the low-level side, it understands functions, structures, arrays, etc. Front-ends translate compiled forms of languages like Java (the main focus) and C# into my IR...

help with reader monad

I am new at haskell, I have to write a program context-aware,so I thought I can use the Reader Monad for keeping the context read from a file, I know how to read the file puting the content in a list of tuplessomething like [([Char],[Char])], but I do not know how to implement the Reader Monad for making the environment available to all...

Overuse of fromIntegral in Haskell

Hey, Whenever I write a function using doubles and integers, I find this problem where I am constantly having to use 'fromIntegral' everywhere in my function. For example: import Data.List roundDouble :: Double -> Int -> Double roundDouble x acc = fromIntegral (round $ x * 10 ** fromIntegral acc) / 10 ** fromIntegral acc ...

Is Concurrent Haskell still restricted to a single OS thread?

In a 2005 research paper it said Concurrent Haskell is currently implemented only for a uni-processor. The runtime schedules lightweight Haskell thread within a single operating system thread. Haskell threads are only suspended at well-defined “safe points”; they cannot be pre-empted at arbitrary moments. Has this changed or is Co...

strange behavior reading a file

I am writing a program in Haskell here it is the code module Main where import IO import Maybe import Control.Monad.Reader --il mio environment consiste in una lista di tuple/coppie chiave-valore data Environment = Env {variables::[(String,String)]}deriving (Show) fromEnvToPair :: Environment-> [(String,String)] fromEnvToPair (Env e)= ...

Programmatically search + replace in a .doc

If I'm given a .doc file with special tags in it such as [first_name], how do I go about replacing all occurrences of it with something like "Clark"? A simple binary replacement only works if the replacement string is the exact same length. Haskell, C, and C++ answers would be best, but any compiled language would do. I'd also prefer to...

Converting .rtf to .pdf in Haskell

The title really says it all! I have a .rtf document (with an image, it's not just text), what haskell libraries are there out there to help me in my quest, or is it way easier than it appears? ...

Choosing data from a list of tuples in Haskell.

Hey, I have a list of tuples of tuples of type :: [((a, b), (a, b), (a, b))], in Haskell. For some context, the 3 points (a, b) represent a (time, value) pair on a U shaped curve with the first point, at the initial time t1 having a maximum value on the curve x1, the third point with a greater time t3=t1+dt and a value x3 I would like...

How to get only the object file without main function by ghc?

[Source Code] data FooBar = Foo | Bar [Command] $ ghc -c foo_bar.hs foo_bar.hs:1:0: The function 'main' is not defined in module 'Main' [Configuration] Glasgow Haskell Compiler, Version 6.12.3, for Haskell 98, stage 2 booted by GHC version 6.10.4 ...

How to create a polyvariadic haskell function?

I need a function which takes an arbitrary number of arguments (All of the same type), does something whith them and afterwards gives a result back. A list of arguments is impracticable in my specific case. As I looked through the haskell libs, there is the function printf from module Text.Printf, which uses a similar trick. Poorly I co...

Executing a system command in Haskell

How could I execute a system command such as cp somefile somedestination in Haskell? Something like an os.Exec. ...

LHS and Markdown: Codeblocks

I happen to really like Markdown (probably because of SO) and I like programming in Haskell. I have recently discovered Literate Haskell (LHS) and I want to use Markdown and LHS together. Let me give you this dumb example: Crazy Literate Haskell ====================== This is an example of some literate Haskell Code: > module Main whe...

Could not find module `Control.Monad.Reader'

Today when I tried to compile my code in Geany I got this error Could not find module `Control.Monad.Reader': it was found in multiple packages: monads-fd-0.1.0.1 mtl-1.1.0.2 Compilation failed. I get the same for the Writer monad; I thought I should remove one of those packages, but I do not want to break other packages, so now wha...

Pattern matching variables in a case statement in Haskell

If I compare a string literal to a string literal using the case statement, I get the expected behavior: if they are the same - it matches, if they are not - it does not. However, if I compare a string literal to a constant that is a string, I get "Pattern matches are overlapped" warning and the branch with the constant always matches. ...

Where are the functional gui users?

There has been a lot of research into ways of creating guis in a functional language. There is libraries for push/pull frp, arrow based frp and probably other superior research too. Many people seem to agree this is the more native way yet just about everyone seems to be using imperative binding libraries such as gtk2hs and wxhaskell. Ev...

Haskell list help!

Hi guys, I'm struggling with Haskell programming. I've got the list below and I want to make it stack on each other, so it'd be like 3 x 4 pixel image. eg: and how can I change the value of the first row or second ... eg: say like I want to make it darker or whiter (0 represents black and 255 represents white) type Pixel = Int type...

Haskell concurrency IO behavior

I am trying to understand concurrency in Haskell more deeply. I have the following code: import Control.Concurrent main :: IO () main = do arr <- return $ [1..9] t <- newMVar 1 forkIO (takeMVar t >> (print.show) arr >> putMVar t 1) forkIO (takeMVar t >> (print.show) arr >> putMVar t 1) forkIO (takeMVar t >...

Stdin as IO Handle

Hey guys, this may be a stupid question but i couldn't find answer anywhere. I'm a Haskell newbie and i'm having trouble with I/O. I have this structure: data SrcFile = SrcFile (IO Handle) String srcFileHandle :: SrcFile -> IO Handle srcFileHandle (SrcFile handle _) = handle srcFileLine :: SrcFile -> String srcFileLine (SrcFile _ st...

Purely functional concurrent skip list

Skip lists (Pugh, 1990) provide sorted dictionaries with logarithmic-time operations like search trees but skip lists are much more amenable to concurrent updates. Is it possible to create an efficient purely functional concurrent skip list? If not, is it possible to create any kind of efficient purely functional concurrent sorted dicti...