haskell

Predicate Logic in Haskell

I've been using the following data structure for the representation of propositional logic in Haskell: data Prop = Pred String | Not Prop | And Prop Prop | Or Prop Prop | Impl Prop Prop | Equiv Prop Prop deriving (Eq, Ord) Any comments on this structure are welcome. However, now I want to extend ...

Convert time for use in mysql

I am trying to load timestamps into mysql. All my times are UTCTime objects. The HDBC mysql implementation does not seem to like UTCTime objects although internally the documentation says that it treats all times as if they were UTC times. I believe that I need to convert UTCTime to EpochTime since it looks like the HDBC mysql implementa...

What is the best way to convert String to ByteString

What is the best way to convert a String to a ByteString in Haskell? My gut reaction to the problem is import qualified Data.ByteString as B import Data.Char (ord) packStr = B.pack . map (fromIntegral . ord) But this doesn't seem satisfactory. ...

Haskell typeclass inheritance and parametric typeclass

Hi! I wish to say that a certain parametrized monad st works with a regular memory, but a subclass of my parametrized monad should impose an additional constraint on the type of memory. In code: class Memory m where ... class State st where unit :: Memory m => a -> st m m a bind :: (Memory m1, Memory m2, Memory m3) => st m1...

Iteration of a randomized algorithm in fixed space and linear time

I used to ask a similar question once. Now I'll be more specific. The purpose is to learn a Haskell idiom to write iterative algorithms with monadic results. In particular, this might be useful for implementing all kinds of randomized algorithms, such as genetic algorithms and a like. I wrote an example program that manifests my problem...

What is GHCi's default implementation of MonadError?

Consider the following test function: testError :: (Error e, MonadError e m) => Bool -> m () testError True = return () testError False = throwError $ strMsg "hello world" At the GHCi prompt, I can do the following: *Main> testError False :: Either String () Left "hello world" *Main> testError True :: Either String () Right () Bec...

Understanding Haskell accessor functions

I'm reading up on Monad tutorials, and the one I'm working on now is http://www.muitovar.com/monad/moncow.xhtml , but I ran on a problem with the state Monad, or to be more precise the runState accessor function. The type is defined as newtype State s a = State { runState :: (s -> (a,s)) } and it's called e.g. runState (chncasews...

Haskell: How is <*> pronounced?

Sorry, I don't really know my math, so I'm curious how to pronounce the functions in the Applicative typeclass: (<*>) :: f (a -> b) -> f a -> f b (*>) :: f a -> f b -> f b (<*) :: f a -> f b -> f a (That is, if they weren't operators, what might they be called?) As a side note, if you could rename pure to something more friendly to...

In GHC, is there a way to print the exports of module?

If I want to see what exports there are from Test.QuickCheck, for example, is there a command I can issue to GHCI to do this? ...

Implicit type parameters in Haskell class definition?

It normally seems the following is illegal: class Foo a where foo :: a -> b -> a Which makes sense; how do we know what b is? However, if we look at Functor's definition: class Functor f where fmap :: (a -> b) -> f a -> f b we see a and b showing up even though we only specify f as a type variable. I'm guessing this is all...

What is the correct type declaration for this function?

The following function will not load: charName :: a -> String charName 'a' = "Alpha" charName 'b' = "Bravo" charName 'c' = "Charlie" charName 'd' = "Delta" charName 'e' = "Echo" charName 'f' = "Foxtrot" charName 'g' = "Golf" charName 'h' = "Hotel" charName 'i' = "India" charName 'j' = "Juliet" charName 'k' = "Kilo" charName 'l' = "Lima"...

What's the next step to learning Haskell after monads?

I've been gradually learning Haskell, and even feel like I've got a hang of monads. However, there's still a lot of more exotic stuff that I barely understand, like Arrows, Applicative, etc. Although I'm picking up bits and pieces from Haskell code I've seen, it would be good to find a tutorial that really explains them wholly. (There se...

Functional proofs (Haskell)

I failed at reading RWH; and not one to quit, I ordered Haskell: The Craft of Functional Programming. Now I'm curious about these functional proofs on page 146. Specifically I'm trying to prove 8.5.1 sum (reverse xs) = sum xs. I can do some of the induction proof but then I get stuck.. HYP: sum ( reverse xs ) = sum xs BASE: sum ( r...

deducing type of multi-parameter type class

I'm trying to get the following code to compile import IO data MyInt = MyInt Int data MyString = MyString String deriving Show class Show b => MyClass a b where fn :: a -> b instance MyClass MyInt MyString where fn (MyInt i) = MyString (show i) myprint :: (MyClass a b) => a -> IO () myprint a = putStrLn $ show (fn a) main ...

Memory footprint of Haskell data types

How to find the actual amount of memory required to store a value of some data type in Haskell (mostly with GHC)? Is it possible to evaluate it in runtime (e.g. in GHCi) or is it possible to estimate memory requirements of a compound data type from its components? In general, if memory requirements of types a and b are known, what is me...

debug output of game objects in Haskell/Yampa and HOOD

I'm stuck with generating debug output for my game objects using Haskell/Yampa (=Arrows) (with HOOD). My engine basically runs a list of game objects which produce Output states (line, circle) which are then rendered. data Output = Circle Position2 Double | Line Vector2 output :: [Output] -> IO () output oos = mapM render oos render ...

Cabal installing quickcheck version problem

I'm trying to install quickcheck 2 via cabal on Ubuntu 10.04. No matter what I try to do, I always end up with the following: $ cabal list quickcheck * QuickCheck Synopsis: Automatic testing of Haskell programs Latest version available: 2.1.1.1 Latest version installed: 1.2.0.0 Homepage: http://www.cse.chalmers.se/~koen ...

OOP style inheritance in Haskell

In C# I can declare the following class A { int Field; } class B : A { int Field2; } static int f(A a) { return a.Field; } static int f(B b) { return a.Field + b.Field2; } static void Main(string[] args) { A a = new A() { Field = 1 }; A b = new B() { Field = 1, Field = 2}; Console.WriteLine(f(a) + f(b)); } In H...

How to get ascii value of character in haskell?

Just wondering how to get ascii value of character in haskell? I've tried to use the 'ord' function in ghci, based on what i read here: http://haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Data-Char.html#6 GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading pac...

Haskell function seems to be limiting integer length - i thought it used bignums?

Hi, i've got a short haskell function here that is supposed to convert "ABCDEF" into 0x41,0x42,0x43,0x44,0x45,0x46 (their ascii values), then multiply them so it becomes 0x4142,4344,4546 but it seems to be limiting integer length - i thought haskell used arbitrary bignums? The last line of the code works fine, which puzzles me Any idea...