haskell

Haskell to F# - declare a recursive types in f#

I am trying to teach my self F# by porting some Haskell Code. Specifily I am trying to port the Countdown Problem shown here The Haskell Code is listed here I am trying to create the following Haskell types in F#: data Op = Add | Sub | Mul | Div data Expr = Val Int | App Op Expr Expr In F# I think Op type is defined as fo...

Using stdout/stderr/stdin streams behind haskell's FFI

I'm developing a small haskell program that uses an external static library I've developed in C++. It accesses the lib through ghc's FFI (foreign function interface). Inside this library I would like to do some output to the console. However, it looks to me like the c++ side of things does not have a correct handle to stdout because outp...

Convert list of Integers into one Int (like concat) in haskell

Pretty much what the title says. I have a list of Integers like so: [1,2,3]. I want to change this in to the Integer 123. My first thought was concat but that doesn't work because it's of the wrong type, I've tried various things but usually I just end up returning the same list. Any help greatly appreciated. Also I have found a way to ...

Python, Ruby, Haskell - Do they provide true multithreading?

We are planning to write a highly concurrent application in any of the Very-High Level programming languages. 1) Do Python, Ruby, or Haskell support true multithreading? 2) If a program contains threads, will a Virtual Machine automatically assign work to multiple cores (or to physical CPUs if there is more than 1 CPU on the mainboard...

Haskell List Comprehensions guards in F#

What is a way to implement similar functionality in Haskell of List comprehensions with guards in F# for example: factors :: Int -> [Int] factors = [x | x <-[1 .. n], n 'mod' x == 0] factors 15 [1,3,5,15] and posInt :: Int -> [Int] posInt = [n | n > 0] posInt 5 [5] posInt 0 [] ...

Dealing with large files in Haskell

I have a large file (4+ gigs) of, lets just say, 4 byte floats. I would like to treat it as List, in the sense that I would like to be able to use map, filter, foldl, etc. However, instead of producing a new list with the output, I would like to write the output back into the file, and thus only have to load a small portion of the file i...

Haskell map function with where statement in F#

I am trying to port this haskell function to F# subs :: [a] -> [[a]] subs [] = [[]] subs (x:xs) = ys ++ map (x:) ys where ys = subs xs example subs [1,2,3] returns: [[],[3],[2],[2,3],[1],[1,3],[1,2],[1,2,3]] returns all sub sequences of a list, which are given by all possible com...

When is it OK to use an IORef?

One thing that has always confused me is whether or not it's an okay time to use an IORef. Are there any guidelines that should be followed when deciding whether or not to use an IORef for a task? When is a good time to use the State monad over an IORef? ...

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: " ...

Haskell vs. Prolog comparison

What kind of problems is better solved in Prolog than in Haskell? What are the main differences between these two languages? ADDED: Is there a Haskell library (kind of a logical solver) that can mimic Prolog functionality? ...

Returning a decyphered string as part of tuple in Haskell

Hi For project euler 59, I came up with this to return a list of tuples containing the decyphered string and the key used (and yes I know about Data.Bits): module XOR where import Data.List import Data.Char decToBin :: Integer -> [Integer] decToBin x = reverse $ decToBin' x where decToBin' 0 = [] decToBin' y = let (a...

What's new in QuickCheck 2?

What are the major differences between QuickCheck 1 and QuickCheck 2? From looking at Haddock docs I can see that it is split across more modules, coarbitrary has been replaced by the new Fun type and FunArbitrary class (which seems easier to understand to me), and testing monadic code is now supported. What else should I be aware of? ...

How to "unpack" a structure in haskell

I recently came across this problem and found a solution but I'm wondering if there are better (or just more idiomatic) solutions. I have a structure for a colour: data Rgb = Rgb Double Double Double And there is a function I'd like to pass the colour components to individually, actually from Cairo: setSourceRGB :: Double -> Double ...

Is it possible to test the return value of Haskell I/O functions?

Haskell is a pure functional language, which means Haskell functions have no side affects. I/O is implemented using monads that represent chunks of I/O computation. Is it possible to test the return value of Haskell I/O functions? Let's say we have a simple 'hello world' program: main :: IO () main = putStr "Hello world!" Is it poss...

Haskell readFile type problem

Hi, I have some troubles with Haskell type system. Situation: Following program is taking list of filenames on the cmdline For all filename it reads its content using the function readFile Content of each file is passed to inputParser (Parsec) Rest is not so important Main problem is in function read_modules First two statements of th...

Lists in Haskell : data type or abstract data type?

Hi, From what I understand, the list type in Haskell is implemented internally using a linked list. However, the user of the language does not get to see the details of the implementation, nor does he have the ability to modify the "links" that make up the linked list to allow it to point to a different memory address. This, I suppose, ...

Which is a more functional programming language, Haskell or Python?

Had learned Haskell during a Functional Programming course in school. Had found Haskell a bit difficult to work with. Have now worked a lot on Python. Python is quite easy to work with. Python does support some functional programming constructs. Was thinking of revisiting Functional Programming. What would be a better language to code?...

How to match rigid types in a type class instance?

I thought I would try modeling some numerical integration on vector quantities of different dimensionality, and figured that type classes were the way to go. I needed something to define the difference between two values and to scale it by a multiplier (to get the derivative), as well as being able to take the distance function. So far...

Linking to SDL and other libraries in Haskell

How to tell ghc to tell ld to link compiled binaries to SDL library? I have a source.hs : import Prelude import Graphics.UI.SDL as SDL import Data.Maybe import GHC.Word import Control.Applicative ... When I do: ghc source.hs I get a bunch of linking errors similar to this one: pong.o: In function `...

State Monad, sequences of random numbers and monadic code

I'm trying to grasp the State Monad and with this purpose I wanted to write a monadic code that would generate a sequence of random numbers using a Linear Congruential Generator (probably not good, but my intention is just to learn the State Monad, not build a good RNG library). The generator is just this (I want to generate a sequence...