Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  MonadRandom or Control.Monad.Random
      (Brandon S. Allbery KF8NH)
   2. Re:  MonadRandom or Control.Monad.Random (Brent Yorgey)
   3. Re:  MonadRandom or Control.Monad.Random (Michael P Mossey)
   4. Re:  MonadRandom or Control.Monad.Random (Brent Yorgey)
   5. Re:  MonadRandom or Control.Monad.Random (Michael Mossey)
   6. Re:  MonadRandom or Control.Monad.Random (Brent Yorgey)
   7.  type constructors (Michael P Mossey)
   8. Re:  type constructors (Jason Dusek)
   9. Re:  type constructors (Daniel Fischer)
  10.  Haskell OpenGL trouble (Matt f)


----------------------------------------------------------------------

Message: 1
Date: Thu, 30 Jul 2009 20:11:42 -0400
From: "Brandon S. Allbery KF8NH" <allb...@ece.cmu.edu>
Subject: Re: [Haskell-beginners] MonadRandom or Control.Monad.Random
To: Michael P Mossey <m...@alumni.caltech.edu>
Cc: beginners@haskell.org
Message-ID: <b7afeae3-25b4-4308-a034-67116ce5b...@ece.cmu.edu>
Content-Type: text/plain; charset="us-ascii"

On Jul 30, 2009, at 20:04 , Michael P Mossey wrote:
> Where can I find MonadRandom or Control.Monad.Random to install? It  
> doesn't seem to be a system library, I can't find it with cabal or  
> Hoogle.


Cabal should have found http://hackage.haskell.org/package/MonadRandom

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : 
http://www.haskell.org/pipermail/beginners/attachments/20090730/1d009752/PGP-0001.bin

------------------------------

Message: 2
Date: Thu, 30 Jul 2009 22:33:21 -0400
From: Brent Yorgey <byor...@seas.upenn.edu>
Subject: Re: [Haskell-beginners] MonadRandom or Control.Monad.Random
To: beginners@haskell.org
Message-ID: <20090731023321.ga16...@seas.upenn.edu>
Content-Type: text/plain; charset=us-ascii

On Thu, Jul 30, 2009 at 05:04:54PM -0700, Michael P Mossey wrote:
> Where can I find MonadRandom or Control.Monad.Random to install? It doesn't 
> seem to be a system library, I can't find it with cabal or Hoogle.

'cabal install MonadRandom' ought to work.  Note that you may have to
'cabal update' first to make sure cabal has the most up-to-date
package list.  You can also always look at the complete list of
packages on Hackage by going to hackage.haskell.org.

-Brent


------------------------------

Message: 3
Date: Fri, 31 Jul 2009 17:55:43 -0700
From: Michael P Mossey <m...@alumni.caltech.edu>
Subject: Re: [Haskell-beginners] MonadRandom or Control.Monad.Random
To: beginners <beginners@haskell.org>
Message-ID: <4a73928f.4050...@alumni.caltech.edu>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Brent Yorgey wrote:
> On Thu, Jul 30, 2009 at 05:04:54PM -0700, Michael P Mossey wrote:
>> Where can I find MonadRandom or Control.Monad.Random to install? It doesn't 
>> seem to be a system library, I can't find it with cabal or Hoogle.
> 
> 'cabal install MonadRandom' ought to work.  Note that you may have to
> 'cabal update' first to make sure cabal has the most up-to-date
> package list.  You can also always look at the complete list of
> packages on Hackage by going to hackage.haskell.org.
> 
> -Brent
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

That worked.

I'm looking at this example from the docs. I understand most of this but I 
can't 
find a definition of getRandomR. See die has type (Rand g Int) I'm assuming 
getRandomR is a function that has that type, but I can't find its definition.


import Control.Monad.Random

die :: (RandomGen g) => Rand g Int
die = getRandomR (1,6)

dice :: (RandomGen g) => Int -> Rand g [Int]
dice n = sequence (replicate n die)

main = do
   values <- evalRandIO (dice 2)
   putStrLn (show values)





------------------------------

Message: 4
Date: Fri, 31 Jul 2009 21:02:02 -0400
From: Brent Yorgey <byor...@seas.upenn.edu>
Subject: Re: [Haskell-beginners] MonadRandom or Control.Monad.Random
To: beginners@haskell.org
Message-ID: <20090801010202.ga22...@seas.upenn.edu>
Content-Type: text/plain; charset=us-ascii

On Fri, Jul 31, 2009 at 05:55:43PM -0700, Michael P Mossey wrote:
> Brent Yorgey wrote:
>> On Thu, Jul 30, 2009 at 05:04:54PM -0700, Michael P Mossey wrote:
>>> Where can I find MonadRandom or Control.Monad.Random to install? It 
>>> doesn't seem to be a system library, I can't find it with cabal or 
>>> Hoogle.
>>
>> 'cabal install MonadRandom' ought to work.  Note that you may have to
>> 'cabal update' first to make sure cabal has the most up-to-date
>> package list.  You can also always look at the complete list of
>> packages on Hackage by going to hackage.haskell.org.
>>
>> -Brent
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>
> That worked.
>
> I'm looking at this example from the docs. I understand most of this but I 
> can't find a definition of getRandomR. See die has type (Rand g Int) I'm 
> assuming getRandomR is a function that has that type, but I can't find its 
> definition.

getRandomR has type 

  (MonadRandom m, Random a) => (a, a) -> m a

which in particular can be specialized to 

  (RandomGen g) => (Int,Int) -> Rand g Int . 

The documentation for getRandomR, and the other methods of the
MonadRandom class, can be found here:

  
http://hackage.haskell.org/packages/archive/MonadRandom/0.1.3/doc/html/Control-Monad-Random-Class.html

-Brent


------------------------------

Message: 5
Date: Sat, 01 Aug 2009 10:17:20 -0700
From: Michael Mossey <m...@alumni.caltech.edu>
Subject: Re: [Haskell-beginners] MonadRandom or Control.Monad.Random
To: beginners <beginners@haskell.org>
Message-ID: <4a7478a0.1030...@alumni.caltech.edu>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed



Brent Yorgey wrote:
> On Fri, Jul 31, 2009 at 05:55:43PM -0700, Michael P Mossey wrote:

>> I'm looking at this example from the docs. I understand most of this but I 
>> can't find a definition of getRandomR. See die has type (Rand g Int) I'm 
>> assuming getRandomR is a function that has that type, but I can't find its 
>> definition.
> 
> getRandomR has type 
> 
>   (MonadRandom m, Random a) => (a, a) -> m a
> 
> which in particular can be specialized to 
> 
>   (RandomGen g) => (Int,Int) -> Rand g Int . 
> 
> The documentation for getRandomR, and the other methods of the
> MonadRandom class, can be found here:
> 
>   
> http://hackage.haskell.org/packages/archive/MonadRandom/0.1.3/doc/html/Control-Monad-Random-Class.html

Thanks. I'm still getting used to Haskell documentation. I was looking in 
Control.Monad.Random, but I needed to look in Control.Monad.Random.Class.

So I would like to know how to do something which is on the surface 
imperative-like: toss a die until a 1 comes up, and count the number of 
tosses. This would involve some kind of looping with an exit condition in 
an imperative language. Can someone show me how to write that in Haskell?

(Actually I want to do a lot more than that, but I just want to start there.)

Thanks,
Mike


------------------------------

Message: 6
Date: Sat, 1 Aug 2009 13:36:39 -0400
From: Brent Yorgey <byor...@seas.upenn.edu>
Subject: Re: [Haskell-beginners] MonadRandom or Control.Monad.Random
To: beginners@haskell.org
Message-ID: <20090801173639.ga20...@seas.upenn.edu>
Content-Type: text/plain; charset=us-ascii

On Sat, Aug 01, 2009 at 10:17:20AM -0700, Michael Mossey wrote:
>
>
> Brent Yorgey wrote:
>> On Fri, Jul 31, 2009 at 05:55:43PM -0700, Michael P Mossey wrote:
>
>>> I'm looking at this example from the docs. I understand most of this but 
>>> I can't find a definition of getRandomR. See die has type (Rand g Int) 
>>> I'm assuming getRandomR is a function that has that type, but I can't 
>>> find its definition.
>>
>> getRandomR has type 
>>   (MonadRandom m, Random a) => (a, a) -> m a
>>
>> which in particular can be specialized to 
>>   (RandomGen g) => (Int,Int) -> Rand g Int . 
>> The documentation for getRandomR, and the other methods of the
>> MonadRandom class, can be found here:
>>
>>   
>> http://hackage.haskell.org/packages/archive/MonadRandom/0.1.3/doc/html/Control-Monad-Random-Class.html
>
> Thanks. I'm still getting used to Haskell documentation. I was looking in 
> Control.Monad.Random, but I needed to look in Control.Monad.Random.Class.
>
> So I would like to know how to do something which is on the surface 
> imperative-like: toss a die until a 1 comes up, and count the number of 
> tosses. This would involve some kind of looping with an exit condition in 
> an imperative language. Can someone show me how to write that in Haskell?
>
> (Actually I want to do a lot more than that, but I just want to start there.)

You could do something as simple as this:

  tossesUntilOne :: (RandomGen g) => Rand g Int
  tossesUntilOne = do
    tosses <- getRandomRs (1,6)
    return $ length (takeWhile (/= 1) tosses) + 1

That is, instead of writing it as a loop with an exit condition, you
can just generate an infinite list of tosses, then count the length of
the portion before the first 1.

-Brent


------------------------------

Message: 7
Date: Sat, 01 Aug 2009 10:44:49 -0700
From: Michael P Mossey <m...@alumni.caltech.edu>
Subject: [Haskell-beginners] type constructors
To: beginners@haskell.org
Message-ID: <4a747f11.20...@alumni.caltech.edu>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

I was playing around with type constructors and I wrote this:

data Foo a b = Foo1 [a]
              | Foo2 (a -> b)

t3 = Foo1 [1, 2, 3]

I wanted to see what ghci thought the type of t3 was. Essentially, it's data 
that doesn't use all of the type variables. So this ran fine, and

*Main> :t t3
t3 :: Foo Integer b

Wow! The data exists but it doesn't have a "complete type" so to speak. This 
worked, too:

f3 (Foo1 xs) = length xs

*Main> f3 t3
3

This is surprising to a conventional programmer. But does this naturally relate 
to other features of Haskell. Perhaps laziness? (I.e. data of type Foo doesn't 
always need a type b so it just doesn't have one until it needs one.)

Thanks,
Mike



------------------------------

Message: 8
Date: Sat, 1 Aug 2009 11:43:10 -0700
From: Jason Dusek <jason.du...@gmail.com>
Subject: Re: [Haskell-beginners] type constructors
To: Michael P Mossey <m...@alumni.caltech.edu>
Cc: beginners@haskell.org
Message-ID:
        <42784f260908011143r5dc15283x64a8530f7bd24...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

2009/08/01 Michael P Mossey <m...@alumni.caltech.edu>:
> This is surprising to a conventional programmer. But does this
> naturally relate to other features of Haskell. Perhaps
> laziness? (I.e. data of type Foo doesn't always need a type b
> so it just doesn't have one until it needs one.)

  Laziness is a runtime thing; type constraints are compile
  time. So "...doesn't have one until it needs one." isn't right
  -- `t3` will *never* have a type for `b` in the program
  snippet above. If you add more code (create a different
  context) then you might constrain `b` more and lead to a more
  definite type. The type is always a static type, though --
  types don't get more specific as the program runs.

--
Jason Dusek


------------------------------

Message: 9
Date: Sat, 1 Aug 2009 21:00:45 +0200
From: Daniel Fischer <daniel.is.fisc...@web.de>
Subject: Re: [Haskell-beginners] type constructors
To: beginners@haskell.org
Message-ID: <200908012100.46173.daniel.is.fisc...@web.de>
Content-Type: text/plain;  charset="iso-8859-1"

Am Samstag 01 August 2009 19:44:49 schrieb Michael P Mossey:
> I was playing around with type constructors and I wrote this:
>
> data Foo a b = Foo1 [a]
>
>               | Foo2 (a -> b)
>
> t3 = Foo1 [1, 2, 3]
>
> I wanted to see what ghci thought the type of t3 was. Essentially, it's
> data that doesn't use all of the type variables. So this ran fine, and
>
> *Main> :t t3
> t3 :: Foo Integer b

Actually, the type of t3 could be
t3 :: Num a => Foo a b

but without a type signature the monomorphism restriction applies and a is 
defaulted to 
Integer.

*MFoo> :t Foo2 even
Foo2 even :: (Integral a) => Foo a Bool

>
> Wow! The data exists but it doesn't have a "complete type" so to speak.

It does, it has a polymorphic type, or one could say it has many types:

*MFoo> :t [t3,Foo2 even]
[t3,Foo2 even] :: [Foo Integer Bool]
*MFoo> :t [t3,Foo2 id]
[t3,Foo2 id] :: [Foo Integer Integer]
*MFoo> :t (t3 :: Foo Integer Bool)
(t3 :: Foo Integer Bool) :: Foo Integer Bool
*MFoo> :t (t3 :: Foo Integer Char)
(t3 :: Foo Integer Char) :: Foo Integer Char
*MFoo> :t (t3 `asTypeOf` (Foo2 even))
(t3 `asTypeOf` (Foo2 even)) :: Foo Integer Bool
*MFoo> :t (t3 `asTypeOf` (Foo2 id))
(t3 `asTypeOf` (Foo2 id)) :: Foo Integer Integer

> This worked, too:
>
> f3 (Foo1 xs) = length xs
>
> *Main> f3 t3
> 3

*MFoo> :t (\(Foo1 xs) -> length xs)
(\(Foo1 xs) -> length xs) :: Foo t1 t -> Int

>
> This is surprising to a conventional programmer. But does this naturally
> relate to other features of Haskell. Perhaps laziness? (I.e. data of type
> Foo doesn't always need a type b so it just doesn't have one until it needs
> one.)

Polymorphism and type inference, not laziness.

>
> Thanks,
> Mike



------------------------------

Message: 10
Date: Sat, 1 Aug 2009 21:02:54 -0500
From: Matt f <gandolfm...@gmail.com>
Subject: [Haskell-beginners] Haskell OpenGL trouble
To: beginners@haskell.org
Message-ID:
        <2717745e0908011902o4a3c4955ydd14141c7ac73...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I am currently running Mac OS 10.5.7, and I have install many Haskell files,
compiled a bouncing ball example, fixed the enableGUI bug, tried an IDE, and
have started installing graphics libraries.
I am using Cabal in the terminal to install what I need, though whenever I
try to install opengl or a package of opengl; it comes up with an error.

Macintosh-2:opengl matthew$ sudo cabal install
Resolving dependencies...
Configuring OpenGLRaw-1.0.1.0...
cabal: Missing dependency on a foreign library:
* Missing C library: GL
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:
GLURaw-1.0.0.0 depends on OpenGLRaw-1.0.1.0 which failed to install.
OpenGL-2.3.0.0 depends on OpenGLRaw-1.0.1.0 which failed to install.
OpenGLRaw-1.0.1.0 failed during the configure step. The exception was:
exit: ExitFailure 1
Macintosh-2:opengl matthew$

It appears that I have zoned onto the bit that's causing all this mess, I'm
missing a C library: GL.
Unfortunately after googling a while I have found no answer.

Am I doing something wrong? Is there another way? Could there be a fix?


Thanks,
-Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090801/f025e7bd/attachment.html

------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 14, Issue 1
****************************************

Reply via email to