haskell

unboxing, (sparse) matrices, and haskell vector library

I would like to manipulate matrices (full or sparse) efficiently with haskell's vector library. Here is a matrix type import qualified Data.Vector.Unboxed as U import qualified Data.Vector as V data Link a = Full (V.Vector (U.Vector a)) | Sparse (V.Vector (U.Vector (Int,a))) type Vector a = U.Vector a As you can see, the matrix...

Haskell and random numbers

Hi, I've been messing with Haskell few days and stumbled into a problem. I need a method that returns a random list of integers ( Rand [[Int]] ). So, I defined a type: type Rand a = StdGen -> (a, StdGen). I was able to produce Rand IO Integer and Rand [IO Integer] ( (returnR lst) :: StdGen -> ([IO Integer], StdGen) ) somehow. Any tip...

How do you make this Haskell power function tail recursive?

turboPower a 0 = 1 turboPower a b | even b = turboPower (a*a) (b `div` 2) | otherwise = a * turboPower a (b-1) THANKS! ...

Safe and polymorphic toEnum

I'd like to write a safe version of toEnum: safeToEnum :: (Enum t, Bounded t) => Int -> Maybe t A naive implementation: safeToEnum :: (Enum t, Bounded t) => Int -> Maybe t safeToEnum i = if (i >= fromEnum (minBound :: t)) && (i <= fromEnum (maxBound :: t)) then Just . toEnum $ i else Nothing main = do print $ (safeToEnu...

Is there any working implementation of reverse mode automatic differentiation for Haskell?

The closest-related implementation in Haskell I have seen is the forward mode at http://hackage.haskell.org/packages/archive/fad/1.0/doc/html/Numeric-FAD.html. The closest related related research appears to be reverse mode for another functional language related to Scheme at http://www.bcl.hamilton.ie/~qobi/stalingrad/. I see reverse ...

haskell recursive function

Hello, Please help me with writing function which takes two arguments : list of ints and index (int) and returns list of integers with negative of value on specified index position in the table MyReverse :: [Int]->Int->[Int] for example myReverse [1,2,3,4,5] 3 = [1,2,-3,4,5] if index is bigger then length of the list or smaller then...

Why toInteger :: Int -> Integer is lazy?

I have the following code: {-# NOINLINE i2i #-} i2i :: Int -> Integer i2i x = toInteger x main = print $ i2i 2 Running GHC with -ddump-simpl flag gives: [Arity 1 NoCafRefs Str: DmdType U(L)] Main.i2i = GHC.Real.toInteger1 Seems that conversion from Int to Integer is lazy. Why is it so - is there a case when I can have (toInteg...

How do functional programming languages work?

I was just reading this excellent post, and got some better understanding of what exactly object oriented programming is, how Java implements it in one extreme manner, and how functional programming languages are a contrast. What I was thinking is this: if functional programming languages cannot save any state, how do they do s...

How can I make a Maybe-Transformer MaybeT into an instance of MonadWriter?

I am trying to build a MaybeT-Transformer Monad, based on the example in the Real World Haskell, Chapter Monad Transformers: data MaybeT m a = MaybeT { runMT :: m (Maybe a) } instance (Monad m) => Monad (MaybeT m) where m >>= f = MaybeT $ do a <- runMT m case a of Just x -> runMT (...

Compiled Haskell libraries with FFI imports are invalid when imported into GHCI

I am using GHC 6.12.1, in Ubuntu 10.04 When I try to use the FFI syntax for static storage, only modules running in interpreted mode (ie GHCI) work properly. Compiled modules have invalid pointers, and do not work. I'd like to know whether anybody can reproduce the problem, whether this an error in my code or GHC, and (if the latter) wh...

Haskell Convert Byte String To UTC Time

I have been trying to make a function in Haskell to take a ByteString which is a datetime and convert it to UTC time taking into account the time zone from the original encoding. I am very new to Haskell so I may be making a really basic mistake. convertStringToUtc s = do estTimeZone <- hoursToTimeZone -5 time <- read $ B.unpa...

F# for C#/Haskell programmer

What is recommended tutorial of F# for Haskell programmer? F# seems to borrow a lot from Haskell but there are little traps which makes hard to write. Generally I need walkthrough the F# which would not explain what is the difference between mutable data and immutable (Haskell is much more strict in this area) etc. I know C# a little s...

Haskell Binary Tree Function (map)

How can i define a Haskell function which will apply a function to every value in a binary tree? So i know that it is similar to the map function - and that its type would be: mapT :: (a -> b) -> Tree a -> Tree b but thats about it... ...

Flowcharting functional programming languages

Flowcharting. This ancient old practice that's been in use for over 1000 years now, being forced upon us poor students, without any usefulness (or so do I think). It might work well with imperative, sequentially running languages, but what about my beloved functional programming? Sadly, I'm forced to create a flow chart for my programm ...

Has anyone ever encountered a Monad Transformer in the wild?

In my area of business - back office IT for a financial institution - it is very common for a software component to carry a global configuration around, to log it's progress, to have some kind of error handling / computation short circuit... Things that can be modelled nicely by Reader-, Writer-, Maybe-monads and the like in Haskell and ...

using haskell for "business applications"

Hello, I would like to know if there is any posiibility that I can use Haskell with small database like sql server compact so that client wont have to install any server on his desktop. Is there any api providing sql statements and so on ... What is the best solution to achieve small database application using haskell. thanks for help...

Finding maximum of a list of lists by sum of elements in Python

What's the idiomatic way to do maximumBy (higher order function taking a comparison function for the test), on a list of lists, where the comparison we want to make is the sum of the list, in Python? Here's a Haskell implementation and example output: > maximumBy (compare `on` sum) [[1,2,3],[4,5,6],[1,3,5]] > [4,5,6] And implementati...

Multithreaded Haskell

Hi I'm learning Haskell and I'd like to write some multithreaded programs now to see the performance gains from that in a functional language. I can find some references to it on the internet but never a proper introduction to it. Can anyone point me to a guide which is understandable for someone who knows the syntax fairly well, but is ...

For reliable code, NModel, Spec Explorer, F# or other?

I've got a business app in C#, with unit tests. Can I increase the reliability and cut down on my testing time and expense by using NModel or Spec Explorer? Alternately, if I were to rewrite it in F# (or even Haskell), what kinds (if any) of reliability increase might I see? Code Contracts? ASML? I realize this is subjective, and p...

run wxHaskell on other machine

Hello, I've compiled haskell program which uses wxHaskell library, now I would like to know how to make it run on other machines which doesn't have wxHaskell installed. Of course I can see errors and I can copy dlls written in output and copy them to that machine but what is professioal sollution, can I write any installer or something l...