Re: [Haskell-cafe] OpenGL: No instance for Random GLfloat

2012-05-02 Thread Mark Spezzano
Hi,

I tried this but now I get another error:

The data constructors of `GLfloat' are not all in scope
  so you cannot derive an instance for it
In the stand-alone deriving instance for `Random GLfloat'

Mark

On 03/05/2012, at 10:39 AM, Patrick Palka wrote:

> Because GLfloat is simply a newtype wrapper for CFloat, which has a Random 
> instance, I would do:
> 
> {-# LANGUAGE StandaloneDeriving #-}
> {-# LANGUAGE GeneralizedNewtypeDeriving #-}
> deriving instance Random GLFloat
> 
> On Wed, May 2, 2012 at 6:29 PM, Mark Spezzano  
> wrote:
> Hi Haskellers,
> 
> I'm trying to generate a random vertex in OpenGL as follows.
> 
> genPosition :: IO (Vertex3 GLfloat)
> genPosition = do x <- getStdRandom $ randomR (-1.6,1.6)
>   y <- getStdRandom $ randomR (-1.0,1.0)
>  return (Vertex3 x y (-1))
> 
> Unfortunately the compiler complains about me having to implement an instance 
> of Random for  GLfloat.
> 
> How do I do this (or avoid having to do this)?
> 
> Cheers,
> 
> Mark
> 
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] OpenGL: No instance for Random GLfloat

2012-05-02 Thread Mark Spezzano
Hi Haskellers,

I'm trying to generate a random vertex in OpenGL as follows.

genPosition :: IO (Vertex3 GLfloat)
genPosition = do x <- getStdRandom $ randomR (-1.6,1.6)
   y <- getStdRandom $ randomR (-1.0,1.0)
  return (Vertex3 x y (-1))

Unfortunately the compiler complains about me having to implement an instance 
of Random for  GLfloat.

How do I do this (or avoid having to do this)?

Cheers,

Mark


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Really Simple explanation of Continuations Needed

2011-10-01 Thread Mark Spezzano
Hi Heinrich, 

I'm really looking to use the Cont monad itself--but the link you gave me is 
also helpful, so thank you.

If anyone else has words of wisdom to add to this thread please feel free to 
pitch in.

Thanks,

Mark 

On 01/10/2011, at 5:08 PM, Heinrich Apfelmus wrote:

> Mark Spezzano wrote:
>> Can someone please give me a _lucid_ and  _simple_ explanation of
>> exactly how continuations can be used in Haskell?
>> I've already had a look at most of the tutorials and explanations on
>> the web, but I'm still confused. Continuations and CPS have me
>> baffled. (I have most of the Haskell textbooks and even these are
>> sketchy on Continuations)
>> I don't understand the notion of the Cont monad and how it can be
>> used for multitasking, backtracking and interrupting computations. I
>> understand that functions  take in a (continuation) function that
>> represents the work remaining to do, but all of the explanations on
>> the web and in technical papers seems to trip over themselves in
>> explaining the fundamentals to a CPS-newbie.
> 
> If you just want to implement multitasking, backtracking or interrupting 
> computations, without continuations, I recommend my "Operational Monad 
> Tutorial"
> 
>  http://apfelmus.nfshost.com/articles/operational-monad.html
> 
> The link to the Cont monad is explained at the very end.
> 
> 
> Best regards,
> Heinrich Apfelmus
> 
> --
> http://apfelmus.nfshost.com
> 
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Really Simple explanation of Continuations Needed

2011-09-30 Thread Mark Spezzano
Hi,

Can someone please give me a _lucid_ and  _simple_ explanation of exactly how 
continuations can be used in Haskell?

I've already had a look at most of the tutorials and explanations on the web, 
but I'm still confused. Continuations and CPS have me baffled. (I have most of 
the Haskell textbooks and even these are sketchy on Continuations)

I don't understand the notion of the Cont monad and how it can be used for 
multitasking, backtracking and interrupting computations. I understand that 
functions  take in a (continuation) function that represents the work remaining 
to do, but al of the explanations on the web and in technical papers seems to 
trip over themselves in explaining the fundamentals to a CPS-newbie.

If anyone could explain such concepts to me in unambiguous, clear English then 
this would be very helpful.

Thanks in advance for your help,

Mark


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Array and Ix for custom Graph ADT

2011-08-13 Thread Mark Spezzano
Solved it with your help :)

Thanks for your assistance!

Mark Spezzano

On 14/08/2011, at 8:29 AM, Daniel Fischer wrote:

> On Sunday 14 August 2011, 00:41:33, Mark Spezzano wrote:
>> Hi Antoine,
>> 
>> The first Int field is a unique index, beginning at 1 and increasing by
>> 1 for each unique Node. 
> 
> Then you could use that for indexing, assuming the Ord instance matches.
> 
> range (MyNode x _ _ _, MyNode y _ _ _) = [x .. y]
> index (MyNode x _ _ _, MyNode y _ _ _) (MyNode z _ _ _)
>  | x <= z && z <= y = z-x
>  | otherwise = error ("Index out of range: " ++ show z)
> 
> etc.
> 
>> The second [Int] field is just a list of random
>> numbers associated with that node.
>> 
>> Mark
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Array and Ix for custom Graph ADT

2011-08-13 Thread Mark Spezzano
Hi Antoine,

The first Int field is a unique index, beginning at 1 and increasing by 1 for 
each unique Node. The second [Int] field is just a list of random numbers 
associated with that node.

Mark


On 14/08/2011, at 2:13 AM, Antoine Latter wrote:

> On Sat, Aug 13, 2011 at 4:37 AM, Mark Spezzano
>  wrote:
>> Hi,
>> 
>> I'm creating a Graph data structure, and I want to use the array list 
>> approach, implemented as an Array.
>> 
>> I need my Nodes to be instances of Ix for this to work and my Node type is 
>> roughly as follows:
>> 
>> data Node = MyNode Int [Int] Type1 Type2
>> 
>> (Type1 and Type2 are nullary algebraic datatypes--enumerations in other 
>> words)
>> 
>> How can I "index" the Array with an instance of a Node. I think I need to 
>> make Node an instance of Ix somehow??
>> 
> 
> What do the 'Int' and '[Int]' fields represent in your Node type?
> 
> Antoine
> 
>> Is this a sensible approach? Sample code of the instance declaration for Ix 
>> would be helpful.
>> 
>> 
>> Thanks
>> 
>> Mark Spezzano
>> 
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>> 
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Array and Ix for custom Graph ADT

2011-08-13 Thread Mark Spezzano
Hi,

I'm creating a Graph data structure, and I want to use the array list approach, 
implemented as an Array.

I need my Nodes to be instances of Ix for this to work and my Node type is 
roughly as follows:

data Node = MyNode Int [Int] Type1 Type2

(Type1 and Type2 are nullary algebraic datatypes--enumerations in other words)

How can I "index" the Array with an instance of a Node. I think I need to make 
Node an instance of Ix somehow??

Is this a sensible approach? Sample code of the instance declaration for Ix 
would be helpful.


Thanks

Mark Spezzano
  
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Fractional Part

2011-08-02 Thread Mark Spezzano
Hi Ata,

You could write the following

decimalPart :: Float -> Integer
decimalPart f = read (tail (tail (show (f :: Integer

This basically says "convert f into a String using the show function, and then 
get the tail of that String twice to get rid of  the leading zero and the 
decimal point then read the result back as an Integer".

To use this function you would type at the prompt:

decimalPart 0.123

which gives

123

This is probably not a very elegant solution, but it will work.


Cheers,

Mark


On 03/08/2011, at 8:36 AM, Ata Jafari wrote:

> Hi everyone,
> I'm totally new to Haskell and functional programming. I try to solve some 
> problems from Proejct Euler with Haskell so that I can improve myself in 
> functional programming.
> In the first step I want to write a little code that can give me only the 
> decimal part of a float. For instance:
> if the number is (0.123) I want to obtain only the (123) part to do some 
> processes on that. (I mean the result of this code must be an integer.)
> I don't expect any complete code, any suggestion and help will be appreciated.
> Thanks
> Ata
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [Haskell-beginners] No instance for (Show a)

2011-07-31 Thread Mark Spezzano
Hi,

You might need a class constraint.

instance (Show a) => Show (Stack a) where

This basically lets Haskell know that if your "a" type is Showable then "Stack 
a" is also Showable.

Let me know if this works.

Cheers,

Mark Spezzano


On 31/07/2011, at 6:49 PM, Ovidiu Deac wrote:

> For some reason ghc complains about not being able to call show on an
> Integer (?!?!?)
> 
> Please enlighten me!
> 
> ovidiu
> 
> This is the hspec:
>it "shows one element"
>( show (push 1 EmptyStack) ≡ "Stack(1)")
> 
> ...this is the code:
> 
> data Stack a =
>EmptyStack |
>StackEntry a (Stack a)
>deriving(Eq)
> 
> 
> instance Show (Stack a) where
>show s =
>"Stack(" ⊕ (showImpl s) ⊕ ")"
>where
>showImpl EmptyStack = ""
>showImpl (StackEntry x _) = show x
> 
> ...and this is the error:
> 
> src/Stack.hs:12:22:
>No instance for (Show a)
>  arising from a use of `showImpl'
>In the first argument of `(++)', namely `(showImpl s)'
>In the second argument of `(++)', namely `(showImpl s) ++ ")"'
>In the expression: "Stack(" ++ (showImpl s) ++ ")"
> 
> ___
> Beginners mailing list
> beginn...@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] More QuickCheck Questions

2011-07-25 Thread Mark Spezzano
Hi all,

I still don't understand exactly how the QuickCheck "sized" function is meant 
to work, and what it's useful for. Please explain!

Also, I think that class CoArbitrary can help to generate random *functions 
*(as opposed to values; but tell me if I'm wrong) but I don't see how this 
could be useful.

Also what does shrink do?

Example code of these would be tremendously helpful understanding these 
concepts.

Thanks in advance,

Mark Spezzano


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] QuickCheck Questions

2011-07-24 Thread Mark Spezzano
Hi Kevin,

Thanks for the response. The first part works well with minor modifications. 

Part 2 is still a bit vague to me. I basically want to "clamp" the Integers 
generated within the Queue to between 0 and some positive number. At present 
they're giving me numbers all over the place (specifically negative number)

Thanks

Mark


On 25/07/2011, at 4:44 AM, Kevin Quick wrote:

> On Sun, 24 Jul 2011 07:30:56 -0700, Mark Spezzano 
>  wrote:
> 
>> Hi all,
>> 
>> I would appreciate it if someone can point me in the right direction with 
>> the following problem.
>> 
>> I'm deliberately implementing a naive Queues packages that uses finite lists 
>> as the underlying representation. I've already read through Hughes' paper 
>> and the article in The Fun of Programming, but I'm still having some 
>> difficulties. Specifically:
>> 
>> 1. I have a newtype Queue a = Queue [a] and I want to generate Queues of 
>> random Integers that are also of random size. How do I do this in 
>> QuickCheck? I guess that  I need to write a generator and then make my 
>> "Queue a" concrete type an instance of Arbitrary? How?
> 
> Mark,
> 
> One of the great things about QuickCheck is that it is automatically 
> compositional.
> What I mean by this is that all you need in your instance is how to form a 
> "Queue [a]" given "[a]", because there are already QuickCheck instances for 
> forming lists, and as long as a is pretty standard (Integers is fine) then 
> there's likely an Arbitrary instance for that as well.
> 
> So (from my head, not actually tested in GHC):
> 
> import Control.Applicative
> import Test.QuickCheck
> 
> instance Arbitrary Queue where
>   arbitrary = Queue <$> arbitrary
> 
> Then you can use this as:
> 
> testProperty "length is something" propQInts
> 
> propQInts t = length t == 
>where types = (t :: Queue Integers)
> 
> The where clause is a fancy way of specifying what the type of t should be 
> without having to express the overall type of propQInts.  You could use a 
> more conventional type specification as well.
> 
>> 
>> 2. If I wanted to specify/constrain the ranges of random Integers generated, 
>> how would I do this?
> 
> Probably something like this:
> 
> instance Arbitrary Queue where
>arbitrary = do li <- listOf $ arbitrary
>  lr <- liftM $ map rangelimit li
>  return $ Queue lr
>where rangelimit n = case (n < LOW, n > HIGH) of
>   (True,_) -> LOW
>   (_,True) -> HIGH
>   _ -> n
> 
> 
>> 
>> 3. If I wanted to specify/constrain the Queue sizes how would I do this?
> 
> Similar to #2.  Perhaps:
> 
>   arbitrary = arbitrary >>= (return . Queue . take CNT . listOf)
> 
> 
> -- 
> -KQ
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] QuickCheck Questions

2011-07-24 Thread Mark Spezzano
Hi all,

I would appreciate it if someone can point me in the right direction with the 
following problem.

I'm deliberately implementing a naive Queues packages that uses finite lists as 
the underlying representation. I've already read through Hughes' paper and the 
article in The Fun of Programming, but I'm still having some difficulties. 
Specifically:

1. I have a newtype Queue a = Queue [a] and I want to generate Queues of random 
Integers that are also of random size. How do I do this in QuickCheck? I guess 
that  I need to write a generator and then make my "Queue a" concrete type an 
instance of Arbitrary? How?

2. If I wanted to specify/constrain the ranges of random Integers generated, 
how would I do this?

3. If I wanted to specify/constrain the Queue sizes how would I do this?

On a separate issue, I also see that QuickCheck 2 has some features not 
discussed anywhere. For example "Coarbitrary" and "shrink" are a bit of a 
mystery to me.

Any code examples for any of the above questions would help greatly.

I've been stuck on this problem for hours. :)

Cheers,

Mark


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Lambda Calculus: Bound and Free formal definitions

2010-12-29 Thread Mark Spezzano
Hi all,

Thanks for your comments

Maybe I should clarify...

For example,

5.2 FREE:

If E1 = \y.xy then x is free
If E2 = \z.z then x is not even mentioned

So E = E1 E2 = x (\z.z) and x is free as expected
So E = E2 E1 = \y.xy and x is free as expected

5.3 BOUND:
=
If E1 = \x.xy then x is bound
If E2 = \z.z then is not even mentioned

So E = E1 E2 = (\x.xy)(\z.z) = (\z.z)y -- Error: x is not bound but should be 
by the rule of 5.3
So E = E2 E1 = (\z.z)(\x.xy) = (\x.xy) then x is bound.

Where's my mistake in the second-to-last example? Shouldn't x be bound 
(somewhere/somehow)?

Thanks,

Mark
 

On 30/12/2010, at 1:52 PM, Mark Spezzano wrote:

> Duh, Sorry. Yes, there was a typo
> 
> the second one should read
> 
> If E is a combination E1 E2 then X is bound in E if and only if X is bound in 
> E1 or is bound in E2.
> 
> Apologies for that oversight!
> 
> Mark
> 
> 
> On 30/12/2010, at 1:21 PM, Antoine Latter wrote:
> 
>> Was there a typo in your email? Because those two definitions appear
>> identical. I could be missing something - I haven't read that book.
>> 
>> Antoine
>> 
>> On Wed, Dec 29, 2010 at 9:05 PM, Mark Spezzano
>>  wrote:
>>> Hi,
>>> 
>>> Presently I am going through AJT Davie's text "An Introduction to 
>>> Functional Programming Systems Using Haskell".
>>> 
>>> On page 84, regarding formal definitions of FREE and BOUND variables he 
>>> gives Defn 5.2 as
>>> 
>>> The variable X is free in the expression E in the following cases
>>> 
>>> a) 
>>> 
>>> b) If E is a combination E1 E2 then X is free in E if and only if X is free 
>>> in E1 or X is free in E2
>>> 
>>> c) 
>>> 
>>> Then in Defn 5.3 he states
>>> 
>>> The variable X is bound in the expression E in the following cases
>>> 
>>> a) 
>>> 
>>> b) If E is a combination E1 E2 then X is free in E if and only if X is free 
>>> in E1 or X is free in E2.
>>> 
>>> c) 
>>> 
>>> Now, are these definitions correct? They seem to contradict each 
>>> otherand they don't make much sense on their own either (try every 
>>> combination of E1 and E2 for bound and free and you'll see what I mean). If 
>>> it is correct then please give some examples of E1 and E2 showing exactly 
>>> why. Personally I think that there's an error in the book.
>>> 
>>> You can see the full text on Google Books (page 84)
>>> 
>>> Thanks for reading!
>>> 
>>> Mark Spezzano
>>> 
>>> 
>>> ___
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe@haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>> 
>> 
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>> 
>> 
> 
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Lambda Calculus: Bound and Free formal definitions

2010-12-29 Thread Mark Spezzano
Duh, Sorry. Yes, there was a typo

the second one should read

If E is a combination E1 E2 then X is bound in E if and only if X is bound in 
E1 or is bound in E2.

Apologies for that oversight!

Mark


On 30/12/2010, at 1:21 PM, Antoine Latter wrote:

> Was there a typo in your email? Because those two definitions appear
> identical. I could be missing something - I haven't read that book.
> 
> Antoine
> 
> On Wed, Dec 29, 2010 at 9:05 PM, Mark Spezzano
>  wrote:
>> Hi,
>> 
>> Presently I am going through AJT Davie's text "An Introduction to Functional 
>> Programming Systems Using Haskell".
>> 
>> On page 84, regarding formal definitions of FREE and BOUND variables he 
>> gives Defn 5.2 as
>> 
>> The variable X is free in the expression E in the following cases
>> 
>> a) 
>> 
>> b) If E is a combination E1 E2 then X is free in E if and only if X is free 
>> in E1 or X is free in E2
>> 
>> c) 
>> 
>> Then in Defn 5.3 he states
>> 
>> The variable X is bound in the expression E in the following cases
>> 
>> a) 
>> 
>> b) If E is a combination E1 E2 then X is free in E if and only if X is free 
>> in E1 or X is free in E2.
>> 
>> c) 
>> 
>> Now, are these definitions correct? They seem to contradict each 
>> otherand they don't make much sense on their own either (try every 
>> combination of E1 and E2 for bound and free and you'll see what I mean). If 
>> it is correct then please give some examples of E1 and E2 showing exactly 
>> why. Personally I think that there's an error in the book.
>> 
>> You can see the full text on Google Books (page 84)
>> 
>> Thanks for reading!
>> 
>> Mark Spezzano
>> 
>> 
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>> 
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Lambda Calculus: Bound and Free formal definitions

2010-12-29 Thread Mark Spezzano
Hi,

Presently I am going through AJT Davie's text "An Introduction to Functional 
Programming Systems Using Haskell".

On page 84, regarding formal definitions of FREE and BOUND variables he gives 
Defn 5.2 as 

The variable X is free in the expression E in the following cases

a) 

b) If E is a combination E1 E2 then X is free in E if and only if X is free in 
E1 or X is free in E2

c) 

Then in Defn 5.3 he states

The variable X is bound in the expression E in the following cases

a) 

b) If E is a combination E1 E2 then X is free in E if and only if X is free in 
E1 or X is free in E2.

c) 

Now, are these definitions correct? They seem to contradict each otherand 
they don't make much sense on their own either (try every combination of E1 and 
E2 for bound and free and you'll see what I mean). If it is correct then please 
give some examples of E1 and E2 showing exactly why. Personally I think that 
there's an error in the book.

You can see the full text on Google Books (page 84)

Thanks for reading!

Mark Spezzano


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] HUnit Control.Exception assertFailure?

2010-11-15 Thread Mark Spezzano
Hi,

I'm trying to follow some examples of HUnit from a webpage. Basically I want my 
_application_ code to call the "error" function when a certain condition is met 
(namely when a supplied String to a function is longer than 80 characters). 

I want my _test_ code to "catch" this error. Unfortunately the example code 
that I'm following uses the older style of Exception handling. Does anyone know 
how to catch this exception using the newer Control.Exception module?

Basically I want to 

1. Call error msg when String length > 80 for some function

2. Catch thrown error from step 1 and do absolutely nothing. (i.e. the 
"expected failure" was caught)

3. If the error is uncaught (in step 2; for whatever reason) then call 
"assertFailure somemsg" and my _test_ code should fail since the error it was 
expecting to occur didn't happen.

Thanks,

Mark Spezzano

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Error installing hp2any-graph on Snow Leopard

2010-11-09 Thread Mark Spezzano
Hi John

Yes, I finally got it (partly) working. I needed to add the 
--extra-lib-dirs= and --extra-include-dirs= flags to point 
to the necessary libraries.

However, now the hp2any-manager won't install because of (other) dependencies. 
So I've given up on it for the time being because it's causing me too much 
trouble. Maybe I'll try again later.

(Strangely it needs _earlier_ versions of cairo and pango and gtk etc, and 
doesn't recognise that I actually have these installed. But when I do this, 
other stuff breaks, and I need to reinstall cabal).

Mark


On 09/11/2010, at 10:24 PM, John Lato wrote:

> From: Mark Spezzano 
> 
> Hi,
> 
> I get the following error when doing a 'cabal install hp2any-graph' (the 
> profiling tool)
> 
> Does anyone know why? (I'm running Snow Leopard and I've tried using other 
> flags suggested...but with no success). GLUT is already installed via 
> MacPorts and via cabal.
> 
> Have you tried to build any Haskell programs using GLUT?  Do they work?
> 
> John
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Combining wl-pprint and ByteString?

2010-11-09 Thread Mark Spezzano
Hi Ivan,

Yes, I want it printed in a terminal window.

I want to be able to run it from the command line in a terminal window, and 
have the text come up in colours (but very fast). My current version is already 
very fast, but I've heard everyone raving about how slow Strings were to use 
for I/O, so I wanted to _experiment_ with ByteStrings to see the performance 
difference.

I'm experimenting with writing a Zork-like text adventure game and I just 
wanted to do some space/time profiling on different pieces of code and observe 
the results. I thought that ByteStrings might be the way to go, but can they be 
combined with the Doc type from the ansi-wl-pprint library? 

Mark

On 09/11/2010, at 5:37 PM, Ivan Lazar Miljenovic wrote:

> On 9 November 2010 17:53, Mark Spezzano  wrote:
>> Hi all,
>> 
>> I want to do the following tasks in this order:
>> 
>> 1. Read text from standard input (should this be stored internally in my 
>> program as a ByteString or as a String?)
>> 
>> 2. Process the text via left justifying it and making it word-wrap (again, 
>> internally, should I store this as a ByteString or String?)
>> 
>> 3. Format the text using the Wadler-Leijen Pretty Printer (to the best of my 
>> knowledge this  only processes Strings, but not ByteStrings)
>> 
>> 4. Print to Standard output the formatted (i.e. colourised, and justified) 
>> text (again, should this be as a ByteString or as a String?)
>> 
>> I thought that the reason that most people use ByteString was for 
>> _performance_, but wl-pprint can only process Strings to the best of my 
>> knowledge.
>> 
>> I would, ideally, like to use ByteStrings everywhere...all throughout my 
>> code. Is this possible with coloured text?
>> 
>> I want to boost up the performance of my application dramatically, so in 
>> theory I could process everything as a String, then as the last second pack 
>> everything processed into a ByteString and print it out...I think that this 
>> might work. Then again it might not because of the types expected. Any help 
>> with this would be appreciated.
> 
> Well, I'm currently working on a Text version of wl-pprint, which will
> probably suit your needs better than Bytestring.
> 
> As for coloured text, there's ansi-wl-pprint, but it's more for
> terminals (how exactly do you want to output your results?).
> 
> 
> -- 
> Ivan Lazar Miljenovic
> ivan.miljeno...@gmail.com
> IvanMiljenovic.wordpress.com
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Combining wl-pprint and ByteString?

2010-11-08 Thread Mark Spezzano
Hi all,

I want to do the following tasks in this order:

1. Read text from standard input (should this be stored internally in my 
program as a ByteString or as a String?)

2. Process the text via left justifying it and making it word-wrap (again, 
internally, should I store this as a ByteString or String?)

3. Format the text using the Wadler-Leijen Pretty Printer (to the best of my 
knowledge this  only processes Strings, but not ByteStrings)

4. Print to Standard output the formatted (i.e. colourised, and justified) text 
(again, should this be as a ByteString or as a String?)

I thought that the reason that most people use ByteString was for 
_performance_, but wl-pprint can only process Strings to the best of my 
knowledge.

I would, ideally, like to use ByteStrings everywhere...all throughout my code. 
Is this possible with coloured text?

I want to boost up the performance of my application dramatically, so in theory 
I could process everything as a String, then as the last second pack everything 
processed into a ByteString and print it out...I think that this might work. 
Then again it might not because of the types expected. Any help with this would 
be appreciated.

Cheers,


Mark Spezzano



 


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Error installing hp2any-graph on Snow Leopard

2010-11-08 Thread Mark Spezzano
Hi Ivan,

I don't think that these flags work with MacPorts--only with cabal.

Mark
On 08/11/2010, at 7:48 PM, Ivan Lazar Miljenovic wrote:

> On 8 November 2010 20:14, Mark Spezzano  wrote:
>> Hi,
>> 
>> I get the following error when doing a 'cabal install hp2any-graph' (the 
>> profiling tool)
>> 
>> Does anyone know why? (I'm running Snow Leopard and I've tried using other 
>> flags suggested...but with no success). GLUT is already installed via 
>> MacPorts and via cabal.
> 
> In this case it needs the glut C library, and you may wish to use
> --extra-{include,lib}-dirs= to specify where MacPorts installs them.
> 
> -- 
> Ivan Lazar Miljenovic
> ivan.miljeno...@gmail.com
> IvanMiljenovic.wordpress.com
> 
> 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Error installing hp2any-graph on Snow Leopard

2010-11-08 Thread Mark Spezzano
Hi,

I get the following error when doing a 'cabal install hp2any-graph' (the 
profiling tool)

Does anyone know why? (I'm running Snow Leopard and I've tried using other 
flags suggested...but with no success). GLUT is already installed via MacPorts 
and via cabal.

Resolving dependencies...
Configuring hp2any-graph-0.5.2...
cabal: Missing dependency on a foreign library:
* Missing C library: glut
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
cabal: Error: some packages failed to install:
hp2any-graph-0.5.2 failed during the configure step. The exception was:
ExitFailure 1

Thanks in advance,

Mark 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Monads and Functions sequence and sequence_

2010-10-29 Thread Mark Spezzano
Not exactly. If you use the type with Maybe Int like so:

sequence [Just 1, Nothing, Just 2]

then the result is Nothing.

Whereas sequence [Just 1, Just 2, Just 3] gives

Just [1, 2, 3]

Why?

I assume there's special implementations of sequence and sequence_ depending on 
the type of monad used. If it's a sequence_ [putStrLn "hello", putStrLn 
"goodbye"] then this prints out hello and goodbye on separate lines.

It seems to work differently for different types.

Mark


On 30/10/2010, at 3:42 PM, Bardur Arantsson wrote:

> On 2010-10-30 07:07, Mark Spezzano wrote:
>> Hi,
>> 
>> Can somebody please explain exactly how the monad functions "sequence" and 
>> "sequence_" are meant to work?
>> 
>> I have almost every Haskell textbook, but there's surprisingly little 
>> information in them about the two functions.
>> 
>> From what I can gather, "sequence" and "sequence_" behave differently 
>> depending on the types of the Monads that they are processing. Is this 
>> correct? Some concrete examples would be really helpful.
>> 
> 
> sequence [m1,m2,m3,m4,...] = do
>  x1 <- m1
>  x2 <- m2
>  x3 <- m3
>  x4 <- m4
>  ...
>  return [x1,x2,x3,x4,...]
> 
> sequence_ [m1,m2,m3,m4,...] = do
>  m1
>  m2
>  m3
>  m4
>  ...
>  return ()
> 
> Cheers,
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Monads and Functions sequence and sequence_

2010-10-29 Thread Mark Spezzano
Hi,

Can somebody please explain exactly how the monad functions "sequence" and 
"sequence_" are meant to work?

I have almost every Haskell textbook, but there's surprisingly little 
information in them about the two functions.

From what I can gather, "sequence" and "sequence_" behave differently depending 
on the types of the Monads that they are processing. Is this correct? Some 
concrete examples would be really helpful.

Even references to some research papers that explain the rationale behind these 
(and all the other..?) monad functions would be great.

Thanks in advance,


Mark Spezzano
 ___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Compiling and installing glib and gtk+ on Snow Leopard

2010-10-23 Thread Mark Spezzano
Hi,

I'm trying to install the Leksah IDE and I've run into the problem that it 
requires glib and gtk+.

Whenever I type 'configure' for glib-2.26.0 everything goes fine.

But when I type 'make' it goes through necessary actions and then suddenly 
stops halfway through stating the following (annoying) error message:

error: #error GNU libiconv not in use but included iconv.h is from libiconv

What, exactly is happening here? I've compiled libiconv and put it under 
/usr/bin (so iconv is there). Yet it still complains...I don't get it. I've 
spend the best part of a day mucking around with this to no avail.

Also: I used to have Leopard installed on my machine and then I upgraded to 
Snow Leopard--does this mean that I would need to rebuild from scratch most of 
the packages on the entire system? Could this change from 32-bit to 64-bit be 
causing an issue?

Thanks,

Mark ___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Correct way to record state in OpenGL?

2010-04-08 Thread Mark Spezzano
Maybe I should ask: If I have many state variables encapsulated in one IO 
(StateVar DemoState) how do I go about referencing and updating _one_ without 
having to enumerate all of them?

What is the syntax?

Mark

On 09/04/2010, at 12:13 AM, Mark Spezzano wrote:

> I sort of understand what people are getting at.
> 
> My basic question is now, given that I have a bunch of parameters that 
> represent state should I bundle up ALL of these parameters in one data type 
> (DemoState, say) and have ONE IORef variable that references the lot, or have 
> an IORef for each piece of state, separately.
> 
> What are the disadvantages of each approach?
> 
> Also, is reading and writing to an IORef expensive computationally?
> 
> Thanks,
> 
> Mark 
> 
> On 05/04/2010, at 2:25 AM, Tobias Brandt wrote:
> 
>> HOpenGL uses Data.StateVar. One can define the following function:
>> 
>> newStateVar :: a -> IO (StateVar a)
>> newStateVar val = do
>> ref <- newIORef val
>> let readAction = readIORef ref
>> let writeAction = \newVal -> writeIORef ref newVal
>> return (makeStateVar readAction writeAction)
>> 
>> Now one can use StateVar consistent with HOpenGL:
>> 
>> create:  foo <- newStateVar bar
>> read: get foo
>> write  foo $= baz
>> 
>> On 4 April 2010 11:03, Mark Spezzano  wrote:
>> Hi
>> 
>> What is the correct way to record "custom" state when using OpenGL?
>> 
>> By this, I refer to, say, properties of a square--say it's x,y coordinates 
>> as it moves across the screen. This requires that the program keep track of 
>> the object's state as it moves. These coordinates are _not_ part of the 
>> OpenGL state machine, so is the correct way to use the State monad?
>> 
>> If so--or if not so--how would I proceed to keep track of the state of my 
>> objects as they move about the screen? Maybe the HOpenGL implementation 
>> comes with such state-tracking devices?
>> 
>> Please post code snippets if necessary.
>> 
>> Thanks in advance,
>> 
>> Mark Spezzano
>>  ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>> 
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Correct way to record state in OpenGL?

2010-04-08 Thread Mark Spezzano
I sort of understand what people are getting at.

My basic question is now, given that I have a bunch of parameters that 
represent state should I bundle up ALL of these parameters in one data type 
(DemoState, say) and have ONE IORef variable that references the lot, or have 
an IORef for each piece of state, separately.

What are the disadvantages of each approach?

Also, is reading and writing to an IORef expensive computationally?

Thanks,

Mark 

On 05/04/2010, at 2:25 AM, Tobias Brandt wrote:

> HOpenGL uses Data.StateVar. One can define the following function:
> 
> newStateVar :: a -> IO (StateVar a)
> newStateVar val = do
> ref <- newIORef val
> let readAction = readIORef ref
> let writeAction = \newVal -> writeIORef ref newVal
> return (makeStateVar readAction writeAction)
> 
> Now one can use StateVar consistent with HOpenGL:
> 
> create:  foo <- newStateVar bar
> read: get foo
> write  foo $= baz
> 
> On 4 April 2010 11:03, Mark Spezzano  wrote:
> Hi
> 
> What is the correct way to record "custom" state when using OpenGL?
> 
> By this, I refer to, say, properties of a square--say it's x,y coordinates as 
> it moves across the screen. This requires that the program keep track of the 
> object's state as it moves. These coordinates are _not_ part of the OpenGL 
> state machine, so is the correct way to use the State monad?
> 
> If so--or if not so--how would I proceed to keep track of the state of my 
> objects as they move about the screen? Maybe the HOpenGL implementation comes 
> with such state-tracking devices?
> 
> Please post code snippets if necessary.
> 
> Thanks in advance,
> 
> Mark Spezzano
>  ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Correct way to record state in OpenGL?

2010-04-04 Thread Mark Spezzano
Hi 

What is the correct way to record "custom" state when using OpenGL?

By this, I refer to, say, properties of a square--say it's x,y coordinates as 
it moves across the screen. This requires that the program keep track of the 
object's state as it moves. These coordinates are _not_ part of the OpenGL 
state machine, so is the correct way to use the State monad?

If so--or if not so--how would I proceed to keep track of the state of my 
objects as they move about the screen? Maybe the HOpenGL implementation comes 
with such state-tracking devices?

Please post code snippets if necessary.

Thanks in advance,

Mark Spezzano
 ___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Using ShowS or Difference Lists

2010-02-06 Thread Mark Spezzano
Hi, 

Just wondering whether I can use ShowS or tupling or Difference Lists to speed 
up the following code?

It's basic text processing. It takes in a list of Lines where each Line is a 
list of Words and intersperses " " between them then concatenates them into a 
longer String. Note that there is a recursive call and the ++ operator.

Thanks

Mark


-- Function: joinLines
-- Joins the Words within Lines together with whitespace and newline characters
-- Argument: Lines to pad with whitespace and newlines
-- Evaluate: The processed and concatenated String   
joinLines :: [Line] -> String 
joinLines (l:[]) = concat (intersperse " " l) 
joinLines (l:ls) = (concat (intersperse " " l)) ++ ('\n':joinLines ls)

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Category Theory woes

2010-02-02 Thread Mark Spezzano
I should probably add that I am trying various proofs that involve injective 
and surjective properties of Hom Sets and Hom functions.

Does anyone know what Hom stands for?

I need a text for a newbie.

Mark

On 02/02/2010, at 9:56 PM, Mark Spezzano wrote:

> Hi all,
> 
> I'm trying to learn Haskell and have come across Monads. I kind of understand 
> monads now, but I would really like to understand where they come from. So I 
> got a copy of Barr and Well's Category Theory for Computing Science Third 
> Edition, but the book has really left me dumbfounded. It's a good book. But 
> I'm just having trouble with the proofs in Chapter 1--let alone reading the 
> rest of the text. 
> 
> Are there any references to things like "Hom Sets" and "Hom Functions" in the 
> literature somewhere and how to use them? The only book I know that uses them 
> is this one. 
> 
> Has anyone else found it frustratingly difficult to find details on 
> easy-to-diget material on Category theory. The Chapter that I'm stuck on is 
> actually labelled Preliminaries and so I reason that if I can't do this, then 
> there's not much hope for me understanding the rest of the book...
> 
> Maybe there are books on Discrete maths or Algebra or Set Theory that deal 
> more with Hom Sets and Hom Functions?
> 
> Thanks,
> 
> Mark Spezzano.
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Category Theory woes

2010-02-02 Thread Mark Spezzano
Hi all,

I'm trying to learn Haskell and have come across Monads. I kind of understand 
monads now, but I would really like to understand where they come from. So I 
got a copy of Barr and Well's Category Theory for Computing Science Third 
Edition, but the book has really left me dumbfounded. It's a good book. But I'm 
just having trouble with the proofs in Chapter 1--let alone reading the rest of 
the text. 

Are there any references to things like "Hom Sets" and "Hom Functions" in the 
literature somewhere and how to use them? The only book I know that uses them 
is this one. 

Has anyone else found it frustratingly difficult to find details on 
easy-to-diget material on Category theory. The Chapter that I'm stuck on is 
actually labelled Preliminaries and so I reason that if I can't do this, then 
there's not much hope for me understanding the rest of the book...

Maybe there are books on Discrete maths or Algebra or Set Theory that deal more 
with Hom Sets and Hom Functions?

Thanks,

Mark Spezzano.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Trapping getChar before echo

2010-02-01 Thread Mark Spezzano
I've tried this example and it just lets me type in anything in CAPITALS, which 
is nice, but Delete key doesn't delete and the arrow keys unfortunately let me 
manoeuvre the cursor all over the screen. Also the biggest problem is that 
Enter doesn't terminate the input session.

Isn't there a simple way to do something like this?

Surely Haskell must have a standard getLine function that support CAPITALS and 
backspacing and no arrow keys. Arrows keys with history would be nice.

Mark


On 31/01/2010, at 11:27 PM, Andrew Coppin wrote:

> Michael Hartl wrote:
>> import System.IO
>> import Data.Char
>> 
>> main = do
>>  hSetEcho stdin False
>>  hSetBuffering stdin NoBuffering
>>  hSetBuffering stdout NoBuffering
>>  scanLine
>>  where scanLine = do   c <- hGetChar stdin
>>  putChar . toUpper $ c
>>  scanLine
>>  
> 
> Last time I tried something like this [on Windows], it didn't seem to work. I 
> wanted to trap arrow keys and so forth, but they seem to be being used for 
> input history. (I.e., pressing the up-arrow produces previously-entered lines 
> of text, and none of this appears to be reaching the Haskell program itself.) 
> Has this changed since I tried it last year?
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Trapping getChar before echo

2010-01-31 Thread Mark Spezzano
Hi,

Is there any way of trapping keystrokes in Haskell, modifying them, and then 
echoing?

Basically I want to give the user a prompt  like:
>

and then have whatever they type appear in UPPERCASE regardless of whether caps 
lock was on or not.

By default Haskell seems to echo characters in whatever case they were typed. I 
want to sneak in a toUpper in before the Chars get echoed.

Thanks

Mark Spezzano


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Parsers for Text Adventures

2010-01-17 Thread Mark Spezzano
Hi,

I am writing a Text Adventure game in Haskell (like Zork)

I have all of the basic parser stuff written as described in Hutton's 
Programming in Haskell and his associated papers. (I'm trying to avoid using 
3rd party libraries, so that I can learn this myself)

Everything that I have works (so far...) except for the following problem:

I want to define a grammar using a series of Verbs like this:

data Verb = Go | Get | Jump | Climb | Give etc, etc deriving (Show, Read)

and then have my parser "get" one of these Verb tokens if possible; otherwise 
it should do something (?) else like give an error message stating "I don't 
know that command"

Now, Hutton gives examples of parsing strings into string whereas I want to 
parse Strings into my Verbs

So, if the user types "get sword" then it will tokenise "get" as type Verb's 
data constructor Get and perhaps "sword" into a Noun called Sword

My parser is defined like this:

newtype Parser a = Parser (String -> [(a, String)])

So I CAN give it a Verb type

but this is where I run into a problem

I've written a Parser called keyword

keyword :: Parser Verb
keyword = do x <- many1 letter
return (read x)

(read this as "take-at-least-one-alphabetic-letter-and-convert-to-a-Verb-type")

which DOES work provided that the user types in one of my Verbs. If they don't, 
well, the whole thing fails with an Exception and halts processing, returning 
to GHCi prompt.

Question: Am I going about this the right way? I want to put together lots of 
"data" types like Verb and Noun etc so that I can build a kind of "BNF grammar".

Question: If I am going about this the right way then what do I about the "read 
x" bit failing when the user stops typing in a recognised keyword. I could 
catch the exception, but typing an incorrect sentence is just a typo, not 
really appropriate for an exception, I shouldn't think. If it IS appropriate to 
do this in Haskell, then how do I catch this exception and continue processing. 

I thought that exceptions should be for exceptional circumstances, and it would 
seem that I might be misusing them in this context.

Thanks

Mark Spezzano

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Referential Transparency and Monads

2009-04-09 Thread Mark Spezzano
Hi,

 

How exactly do monads “solve” the problem of referential transparency? I
understand RT to be such that a function can be replaced with a actual
value. 

 

Since a monad could potentially encapsulate any other value—say, data read
from a keyboard—doesn’t that violate the assumption of RT on monads?

 

Or does RT ignore the encapsulated data and just view the “action” performed
by the monad as the “value” of the monad?

 

Just curious as to the rationale behind referential transparency and how it
applies to monads.

 

Cheers,

 

Mark Spezzano

 


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.557 / Virus Database: 270.11.48/2048 - Release Date: 8/04/2009
7:02 PM
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Definition of "tail recursive" wrt Folds

2009-03-25 Thread Mark Spezzano
Hi,

 

Just looking at the definitions for foldr and foldl I see that foldl is
(apparently) tail recursive while foldr is not.

 

Why?

 

Is it because foldl defers calling itself until last whereas foldr evaluates
itself as it runs?

 

What, strictly speaking, is the definition of ”tail recursive” as opposed to
just “recursive”?

 

Cheers,

 

Mark Spezzano

 


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.557 / Virus Database: 270.11.27/2021 - Release Date: 24/03/2009
4:00 PM
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Ease of Haskell development on OS X?

2009-03-20 Thread Mark Spezzano
Hi,

 

I’ve been thinking of changing over to an iMac from my crappy old PC running
Windows Vista.

 

Question: Does the iMac have good support for Haskell development? 

 

Question: What environment setups do people commonly use (e.g. Eclipse Xcode
etc)?

 

Question: Are there any caveats I should be aware of before changing systems
(i.e. unpleasant surprises).

 

I want to be able to use the machine for Haskell OpenGL programming.

 

Cheers,

 

Mark Spezzano

 


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.557 / Virus Database: 270.11.20/2012 - Release Date: 19/03/2009
12:26 PM
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] OpenGL Linking Issue

2009-03-17 Thread Mark Spezzano
Hi,

 

I hope I’m posting to the right forum. 

 

I’ve got OpenGL up and running on my Windows Vista machine (finally!) and it
runs perfectly well under Eclipse, bringing up a window with a rendered
image as expected.

 

The only issue starts when I try to compile the program without Eclipse
(using GHC rather than GHCi like Eclipse does).

 

I type:

 

C:\Users\Mark\workspace2\OpenGLPractice\src>ghc --make Test1.hs

 

And get the following output

 

Linking Test1.exe ...

C:\Program
Files\Haskell\GLUT-2.1.1.2\ghc-6.10.1/libHSGLUT-2.1.1.2.a(Extensions.

o):fake:(.text+0xcc): undefined reference to `glutgetprocaddr...@4'

collect2: ld returned 1 exit status

 

What’s happening here? Obviously it’s a linking issue, but I was wondering
whether I need to include some library or file or option to ghc so that it
links correctly.

 

Cheers,

 

Mark Spezzano

 


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.557 / Virus Database: 270.11.18/2008 - Release Date: 17/03/2009
4:25 PM
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] OpenGL and Cabal installation

2009-03-17 Thread Mark Spezzano
Hi all,

 

I’m trying desperately to get OpenGL up and running. 

 

I type 

>cabal.exe configure and get the following

 

...

checking GL/glut.h usability... no

checking GL/glut.h presence... no

checking for GL/glut.h... no

checking for GLUT library... no

checking for GL/glut.h... (cached) no

checking GLUT/glut.h usability... no

checking GLUT/glut.h presence... no

checking for GLUT/glut.h... no

configure: error: no GLUT header found, so this package cannot be built

See `config.log' for more details.

 

Where is it looking for these glut.h files? I’ve tried putting them
everywhere in my PATH but msys won’t find them.

 

Cheers,

 

Mark Spezzano 


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.557 / Virus Database: 270.11.18/2008 - Release Date: 17/03/2009
4:25 PM
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] DLL Hell: OpenGL

2009-03-17 Thread Mark Spezzano
Hi all,

 

I’m trying to make the Teapot OpenGL example in Haskell on Windows. It keeps
coming up with this:

 

 

C:\Users\Mark\workspace2\OpenGLPractice\src>ghc --make Teapot

Linking Teapot.exe ...

C:\ghc\ghc-6.10.1\gcc-lib\ld.exe: cannot find -lSM

collect2: ld returned 1 exit status

 

As far as I know, -lSM is to do with XWindows (not windows Vista).How do I
fix this ? What’s going on? I’ve been on this problem now for hours, and all
I wanted to do was get a window up on the screen. Sigh

 

Mark Spezzano


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.557 / Virus Database: 270.11.15/2004 - Release Date: 16/03/2009
7:04 AM
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell, OpenGL on Windows

2009-03-17 Thread Mark Spezzano
Hi,

Can someone PLEASE help me to understand exactly how to configure
OpenGL on Window using Haskell. I'm using Eclipse IDE.

When I try to run the file Test1.hs in GHCi then I get the following
error:
Loading package syb ... linking ... done.
Loading package base-3.0.3.0 ... linking ... done.
Loading package array-0.2.0.0 ... linking ... done.
Loading package containers-0.2.0.0 ... linking ... done.
Loading package OpenGL-2.2.1.1 ... can't load .so/.DLL for: GL
(addDLL: could not load DLL)
Prelude Main>

I've copied the GLUT dll into Windows/System32.

Is there some flag or option that I need to enable to tell Haskell
where to go to link in the library. What do I do with the other .h
and .lib files from GLUT?

Thanks

Mark
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Map in Terms of Fold in terms of Map

2009-03-16 Thread Mark Spezzano
Hi,

 

I’ve noticed that it’s possible to define map as foldr and foldr as a map.
Would this be sensible to define both in terms of each other in the Prelude?
i.e mutually recursive?

 

Cheers,

 

Mark

 


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.557 / Virus Database: 270.11.15/2003 - Release Date: 15/03/2009
2:07 PM
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Default Tuple Orderings

2009-03-15 Thread Mark Spezzano
Hi,

 

Does anyone know how Haskell’s tuple ordering works? Presumably for some
tuple T1 (x1,x2,...xn) and another tuple T2 (y1,y2,...yn) Haskell would
compare T1 and T2 as follows:

 

T1 < T2 if:

x1 < y1 OR otherwise if x1 == y1 then if

x2 < y2 OR otherwise if x2 == y2 then if

x3 < y3 OR otherwise etc

 

xn < yn OR otherwise both tuple are equal

 

In other words my best guess is that the ordering of tuples is by comparing
the first tuple elements and then the seconds, thirds etc, until there’s an
element less than another.

 

Is this reasoning correct?

 

So minimum xs

 

would yield the “smallest” tuple (according to the above rules and if xs is
a list of tuples)?

 

Cheers,

 

Mark Spezzano

 


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.557 / Virus Database: 270.11.13/2001 - Release Date: 14/03/2009
6:54 AM
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Natural Numbers: Best implementation?

2009-03-12 Thread Mark Spezzano
Hi,

 

I was wondering what the best way to implement Natural number would be. Is
there a package which already does this?

 

Here are some options:

 

1.  Don’t bother. Just use Integer.

2.  Use the type 

data Natural = Zero | Succ !Natural

3.  Use the following definition taken from the Gentle Introduction to
Haskell 98

newtype Natural = MakeNatural Integer

toNatural ::Integer-> Integer

toNatural x | x < 0 = error “Can’t create negative naturals!”

 | otherwise = MakeNatural x

fromNatural :: Natural -> Integer

fromNatural (MakeNatural i) = i

 

and then...

 

instance Num Natural where

  fromInteger = toNAtural

  x + y   = toNatural (fromNatural x + fromNatural y)

  x – y   = etc..

  x * y   = etc...

 

Which method is best? So far, I’ve been picking option #1 – just leaving
things as they are and using Integer to keep things simple.

 

I’ve got that feeling that [2] would be fast and [3] would be slow. Comment
appreciated on the merits of each.

 

Cheers,

 

Mark Spezzano

 


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.557 / Virus Database: 270.11.12/1998 - Release Date: 12/03/2009
6:23 PM
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Design Patterns by Gamma or equivalent

2009-03-11 Thread Mark Spezzano
Hi,

 

I’m very familiar with the concept of Design Patterns for OOP in Java and
C++. They’re basically a way of fitting components of a program so that
objects/classes fit together nicely like Lego blocks and it’s useful because
it also provides a common “language” to talk about concepts, like Abstract
Factory, or an Observer to other programmers. In this way one programmer can
instantly get a feel what another programmer is talking about even though
the concepts are fundamentally abstract.

 

Because Haskell is not OO, it is functional, I was wondering if there is
some kind of analogous “design pattern”/”template” type concept that
describe commonly used functions that can be “factored out” in a general
sense to provide the same kind of usefulness that Design Patterns do for
OOP. Basically I’m asking if there are any kinds of “common denominator”
function compositions that are used again and again to solve problems. If
so, what are they called?

 

Cheers,

 

Mark Spezzano

 

 


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.557 / Virus Database: 270.11.9/1993 - Release Date: 10/03/2009
7:19 AM
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Generics Versus Parametric Polymorphism

2009-03-10 Thread Mark Spezzano
Hi,

 

Just wondering if Generics and Parametric polymorphism are one and the same
in Haskell.

 

I read (somewhere!) an article stating that generics might be included in
Haskell Prime but I thought that they’re already included as parametric
polymorphism.

 

Did I misread something? Or is generics in Haskell referring to something
completely different.

 

Cheers,

 

Mark Spezzano

 


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.557 / Virus Database: 270.11.9/1993 - Release Date: 10/03/2009
7:19 AM
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Parallel programming (threads, cores, processors)

2009-03-10 Thread Mark Spezzano
Hi,

 

I’m an experienced software developer, but a bit of a newbie when it comes
to parallel processing in any language.

 

I’ve done some multithreading in Java and C++ on a single processor, single
core architecture only.

 

First, let me define some terms:

 

Multithreading: this is multiple processes running on one processor and is
the conventional way to do parallel programming

Multicore: this is when we have two (or more) cores within the one CPU

Multiprocessor: this is when we have multiple CPUs

 

Question 1:

Is there any programmatic change in dealing with multiple threads as opposed
to multiple cores in most languages (specifically Haskell)?

 

That is, to write multiple threads you normally “spin-off” a new thread
which runs in parallel along with other threads. Is Haskell smart enough to
do this by magic by itself, or would I need to tell it explicitly : Run
thread A whilst running thread B 

 

Also, what about multicore architectures? Do I have to tell the language to
spin off two separate programs to run on each core and then somehow use some
kind of communications to exchange data? 

 

I also assume that, in theory it would be possible to have multiple threads
running on each core. Say, 3 threads spawned from program 1 running on core
1 and 5 threads on program 2 running on core 2

 

Likewise I would suppose that it would be possible to have multiprocessors,
each potentially multicore, each core running multiple threads.

 

Question 2:

 

In light of the above  statement, is the programmatic change DIFFERENT for
dealing with each of 

a)  Multithreading in Haskell versus

b)  Multicores in Haskell verus

c)   Multiprocessors in Haskell

 

 

References or info appreciated.

 

Just curious.

 

Mark

 


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.557 / Virus Database: 270.11.9/1993 - Release Date: 10/03/2009
7:19 AM
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Parallel programming in Haskell (threads, cores, processors)

2009-03-10 Thread Mark Spezzano
Hi,

 

I’m an experienced software developer, but a bit of a newbie when it comes
to parallel processing in any language.

 

I’ve done some multithreading in Java and C++ on a single processor, single
core architecture only.

 

First, let me define some terms:

 

Multithreading: this is multiple processes running on one processor and is
the conventional way to do parallel programming

Multicore: this is when we have two (or more) cores within the one CPU

Multiprocessor: this is when we have multiple CPUs

 

Question 1:

Is there any programmatic change in dealing with multiple threads as opposed
to multiple cores in most languages (specifically Haskell)?

 

That is, to write multiple threads you normally “spin-off” a new thread
which runs in parallel along with other threads. Is Haskell smart enough to
do this by magic by itself, or would I need to tell it explicitly : Run
thread A whilst running thread B 

 

Also, what about multicore architectures? Do I have to tell the language to
spin off two separate programs to run on each core and then somehow use some
kind of communications to exchange data? 

 

I also assume that, in theory it would be possible to have multiple threads
running on each core. Say, 3 threads spawned from program 1 running on core
1 and 5 threads on program 2 running on core 2

 

Likewise I would suppose that it would be possible to have multiprocessors,
each potentially multicore, each core running multiple threads.

 

Question 2:

 

In light of the above  statement, is the programmatic change DIFFERENT for
dealing with each of 

a)  Multithreading in Haskell versus

b)  Multicores in Haskell verus

c)   Multiprocessors in Haskell

 

 

References or info appreciated.

 

Just curious.

 

Mark

 


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.557 / Virus Database: 270.11.9/1993 - Release Date: 10/03/2009
7:19 AM
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Good books on advanced topics

2009-01-31 Thread Mark Spezzano
Hi,

 

Is there a good book on some of the more advanced or esoteric Haskell
topics, like monads, and morphisms, category theory etc.

 

Cheers,

 

Mark

 

 


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.552 / Virus Database: 270.10.12/1910 - Release Date: 22/01/2009
6:28 PM
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe