haskell

Compiling to idiomatic C

Are there any compilers out there for function or lisp-ish languages that compile to idiomatic C? Most compilers out there seem to provide something resembling a machine language composed of C macros. I'm wondering if there is anything out there that can produce readable C code based on a higher-level language. ...

Haskell IO with Numbers

Can anyone help with this exersise? Write a program which asks the user for the base and height of a right angled triangle, calculates its area and prints it to the screen. The interaction should look something like: The base? 3.3 The height? 5.4 The area of that triangle is 8.91 Solved with: getTriArea :: IO Float get...

haskell global var

The task is to create dynamically linked library, which encapsulates database hard work. Due to some design limitations I have a defined interface, which consist of numerous functions. Each function takes a parameters and use them in database query. Database connection should be inside dll and application don't want to bother is there a...

Type Matching in Haskell

If SomeType is defined as: data SomeType = X {myBool :: Bool} | Y {myString :: String} | Z {myString :: String} and I will update an arbitrary X, dependent of his type as follows: changeST :: SomeType -> SomeType changeST (X b) = (X True) changeST (Y s) = (Y "newString") changeST (Z s) = (Z "newStrin...

In Functional Programming, is it considered a bad practice to have incomplete pattern matchings

Is it generally considered a bad practice to use non-exhaustive pattern machings in functional languages like Haskell or F#, which means that the cases specified don't cover all possible input cases? In particular, should I allow code to fail with a MatchFailureException etc. or should I always cover all cases and explicitly throw an er...

Getting Kind mis-match error when trying to use existential quantification

Would like to declare data (Coord a) => Triangle a = Triangle{t0 :: a, t1 :: a, t2 :: a} However I am getting Geometry.hs:15:19:Kind mis-match Expected kind * -> *', but p' has kind *' In the class declaration for Coord' where Coord is defined as class (Traversable p, Functor p, Foldable p, Applicative p) => Coord ...

Haskell: How to type cast

C#: static int F(object x) { return x is string ? 1 : 2; } Haskell? The tricky bit seems to me that Haskell does not have a root type object. Edited: I do not care about converting to string. I want to know how to typecast (for example to see if an object is a Customer or an Order. ...

Having trouble using the BinaryDerive.hs Script, for generating Binary instances

I'm trying to run the BinaryDerive.hs script as per the instructions in the Data.Binary doc, which states: To derive the instance for a type, load this script into GHCi, and bring your type into scope. Your type can then have its Binary instances derived as follows: $ ghci -fglasgow-exts BinaryDerive.hs *BinaryDeri...

How to change properties of DrawingArea in Gtk2Hs

Can someone please point me in the right direction when it comes to changing properties of an element in Gtk2Hs. For example, how do I change the background-color of a DrawingArea? ...

Haskell record syntax and type classes

Suppose that I have two data types Foo and Bar. Foo has fields x and y. Bar has fields x and z. I want to be able to write a function that takes either a Foo or a Bar as a parameter, extracts the x value, performs some calculation on it, and then returns a new Foo or Bar with the x value set accordingly. Here is one approach: class ...

Non-Mainstream Languages, Bad for your resume?

Hi folks, I got my BS in Computer Science about seven years ago. I spent two years in neuroscience research and the next three providing what amounts to tech support. But I love computer programming - and I have since written, as a freelancer, non-trivial commercial code in Haskell, Smalltalk, and Objective-C. I used these languages be...

Reversing binary numbers in Haskell

I have defined data type for Binary numbers as follows data Bin = Nil | O Bin | I Bin deriving (Show, Eq) i want to define a function reverse :: Bin -> Bin so that when i give input like reverse (I (O (I (I Nil)))) i should get the outut I (I (O (I Nil))) that means reversed as input, any body please give me hint how i c...

Adding deriving (Data) to standard types

I would like to add deriving (Data) to standard types. After enabling the StandaloneDeriving, FlexibleContexts, DeriveDataTypeable, and UndecidableInstances extensions, ghc accepts deriving instance Data Day => Data (Day) However, if I do the same thing for DiffTime I get TemperatureRecord.hs:30:0: The data constructors of `Diff...

How long does it take to create 1 million threads in Haskell?

What I understand, Haskell have green threads. But how light weight are they. Is it possible to create 1 million threads? Or How long would it take for 100 000 threads? ...

What are some good books for learning Haskell (and/or OCaml/ML) in particular, and functional programming style in general?

I was spoiled by the excellence of "Programming Ruby" when I was in high school, and ever since I've always looked for a combined introduction & language reference book for every new language I attempt. Note that it doesn't have to be a dead-tree book; any well-written, high-quality resource would be great, regardless of media. This ...

Haskell to Clojure

I am going over this haskell lecture on count down game, i don't know any haskell but i am intrested in the problem, i am trying to port his code to clojure. this is the part i got stuck must be something i don't get in haskell, split :: [a] -> [([a],[a])] split [] = [([],[])] split (x:xs) = ([],x:...

Getting Cabal to work with GHC 6.12.1

I've installed the latest GHC package (6.12.1) on OS X, but I can't get Cabal to work. I've removed the version I had previously that worked with GHC 6.10 and tried to re-install from scratch. The latest Cabal version available for download is 1.6.0.2. However, when I try to build this I get the following error: Configuring Cabal-1.6...

Having trouble writing my fmap

I am trying to write an fmap for this type data Triangle a = Triangle {t0 :: Point a, t1 :: Point a, t2 :: Point a} where Point is defined as data Point a = Point {px :: a, py :: a, pz :: a} And my instance def is instance Functor Triangle where fmap f (Triangle v0 v1 v2) = Triangle (f v0) (f v1) (f v2) I am getting th...

haskell chuncked http reading

Here's the next practical question. I want to download some big files from http server(database updates). This operation should block user UI, preventing him from inputting data. SO the problem is to show user progress bar, which will tell him how much is it still to wait. In python, request objects open file-like object. I have read i...

How to make an unboxed array of floats I can get a Ptr to

I am trying to do some work with HopenGL and I need a Ptr that points to a array of floats. From what I have read uarray and storableArray seem to be the way to go, in some combination some way. ...