Send Beginners mailing list submissions to
        [email protected]

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
        [email protected]

You can reach the person managing the list at
        [email protected]

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


Today's Topics:

   1. Re:  netwire and "dynamic" list of objects (Ertugrul S?ylemez)
   2. Re:  netwire and "dynamic" list of objects (Nathan H?sken)
   3.  PutStrLn (Pierre Michallet)
   4. Re:  PutStrLn (Felipe Almeida Lessa)
   5.  Type of function with constant pattern ([email protected])
   6. Re:  Type of function with constant pattern (Tim Perry)
   7. Re:  Type of function with constant pattern (Mike Meyer)
   8. Re:  Type of function with constant pattern (Brent Yorgey)
   9. Re:  Type of function with constant pattern ([email protected])


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

Message: 1
Date: Tue, 10 Apr 2012 13:57:02 +0200
From: Ertugrul S?ylemez <[email protected]>
Subject: Re: [Haskell-beginners] netwire and "dynamic" list of objects
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

Nathan H?sken <[email protected]> wrote:

> I have a simple SDL based graphic demo, which I am trying (for
> educational purposes) to rewrite utilizing netwire.
>
> The demo basically consists of a State which contains a list of object
> states.
>
> [...]
>
> But I avoided rewriting "updateState" in wire format. But I have no
> Idea how to do that.
> How do I handle a dynamic list of objects in a wire?

Well, you are not really using FRP here.  You are just forcing this
application into the FRP model.  Your only behavior is the application
itself.  This works, but buys you nothing.

The first step to actually making use of FRP here is to get rid of the
concept of "updating" something.  Express your game objects themselves
as wires:

    player :: GameWire (Input, [Wall]) Player
    wall   :: GameWire a Wall
    enemy  :: GameWire (Player, [Wall]) Enemy

This allows you to write static game worlds.  After that you can move to
dynamic game worlds using wire transformers from
Control.Wire.Trans.Combine.  It is also pretty straightforward to write
your own wire transformers for this purpose.  You probably want to do
that later -- just look at the source code.


Greets,
Ertugrul

-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120410/ba34745b/attachment-0001.pgp>

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

Message: 2
Date: Tue, 10 Apr 2012 17:07:47 +0200
From: Nathan H?sken <[email protected]>
Subject: Re: [Haskell-beginners] netwire and "dynamic" list of objects
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Firstly, thanks for the answer.

Ok, I made another attempt. I have a function, to output the state of
one object:

objectWire :: StdGen -> MyWire () ObjectState

The random generator is used to create the initial state. Now I want to
handle a dynamic set of objects. This is my attempt:

wire :: MyWire () State
wire = proc _ -> do
     rec
       rnds <- Wire.delay initRnds -< (tail rnds)
     let rnd = head rnds        --Get a fresh random generator everytime
     --For now, only one new object every call
     let newObjWires = [objectWire rnd]
     rec
       --Start with newObjWires and add newObjWires everytime (1. Error)
       objWires <- Wire.delay newObjWires -< newObjWires ++ objWires


     oss <- distribute objWires -< () -- 2. Error
     Wire.identity -< GameState rnds ss
     where
       initRnds = stdgens $ mkStdGen 0

Now I get
Not in scope: `newObjWires'
at the 1. Error and
Not in scope: `objWires'
at the 2. Error.

OK, I am guessing that I may not use newObjWires/objWires as parameters
to the functions creating the wires.
But I do not understand how to use any of Control.Wire.Trans.Combine to
handle my dynamic set of wires.

Regards,
Nathan


On 04/10/2012 01:57 PM, Ertugrul S?ylemez wrote:
> Nathan H?sken <[email protected]> wrote:
> 
>> I have a simple SDL based graphic demo, which I am trying (for
>> educational purposes) to rewrite utilizing netwire.
>>
>> The demo basically consists of a State which contains a list of object
>> states.
>>
>> [...]
>>
>> But I avoided rewriting "updateState" in wire format. But I have no
>> Idea how to do that.
>> How do I handle a dynamic list of objects in a wire?
> 
> Well, you are not really using FRP here.  You are just forcing this
> application into the FRP model.  Your only behavior is the application
> itself.  This works, but buys you nothing.
> 
> The first step to actually making use of FRP here is to get rid of the
> concept of "updating" something.  Express your game objects themselves
> as wires:
> 
>     player :: GameWire (Input, [Wall]) Player
>     wall   :: GameWire a Wall
>     enemy  :: GameWire (Player, [Wall]) Enemy
> 
> This allows you to write static game worlds.  After that you can move to
> dynamic game worlds using wire transformers from
> Control.Wire.Trans.Combine.  It is also pretty straightforward to write
> your own wire transformers for this purpose.  You probably want to do
> that later -- just look at the source code.
> 
> 
> Greets,
> Ertugrul
> 
> 
> 
> 
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners




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

Message: 3
Date: Tue, 10 Apr 2012 17:57:14 +0200
From: "Pierre Michallet" <[email protected]>
Subject: [Haskell-beginners] PutStrLn
To: "beginners haskell" <[email protected]>
Message-ID: <E64E493C8FAB4E459AA765A4E433D864@medione9995867>
Content-Type: text/plain; charset="iso-8859-1"

I have the impression that putStrLn adjusts its intercharacter spacing 
according to the length of the string to print.
Can someone tell me :
   1 Is it right 
   2 if yes , is there a function which does not apply that kind of 
proportionality

Thank you for your help


Pierre Michallet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120410/aabc75c1/attachment-0001.htm>

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

Message: 4
Date: Tue, 10 Apr 2012 13:06:36 -0300
From: Felipe Almeida Lessa <[email protected]>
Subject: Re: [Haskell-beginners] PutStrLn
To: Pierre Michallet <[email protected]>
Cc: beginners haskell <[email protected]>
Message-ID:
        <CANd=ogh8ut+1s0h-mj91654+mrphd5uw7f685wehju9vofk...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Its definition is just

  putStrLn str = putStr (str ++ "\n")

No kind of formatting is applied.

Cheers,

-- 
Felipe.



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

Message: 5
Date: Tue, 10 Apr 2012 16:57:38 -0300
From: [email protected]
Subject: [Haskell-beginners] Type of function with constant pattern
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Hello.

Given the following function definitions

   f 0 = True

   g False = True

ghc infers the following types for the functions:

   f :: (Eq a, Num a) => a -> Bool
   g :: Bool -> Bool

Why f has "Eq a" in the context in ts type, and g does not?

As both are defined using a constant pattern, I expected none of them
should require the type of the argument to be instance of Eq.

Romildo



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

Message: 6
Date: Tue, 10 Apr 2012 14:16:15 -0700
From: Tim Perry <[email protected]>
Subject: Re: [Haskell-beginners] Type of function with constant
        pattern
To: [email protected]
Message-ID:
        <cafvgaswyworvyrhymkpiuhj+wt15oczcphpktatypfup2at...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I believe that "f 0 = ..." is a guard and the guard is pattern matching on
the constructor. Despite the fact that you don't have an instance of "f _ =
....", the compiler needs an Eq instance to determine if it should run the
"f 0" version of the function.

Does that make sense? Hopefully someone with a better grasp of the topic
will fill in the details.

--Tim

On Tue, Apr 10, 2012 at 12:57 PM, <[email protected]> wrote:

> Hello.
>
> Given the following function definitions
>
>   f 0 = True
>
>   g False = True
>
> ghc infers the following types for the functions:
>
>   f :: (Eq a, Num a) => a -> Bool
>   g :: Bool -> Bool
>
> Why f has "Eq a" in the context in ts type, and g does not?
>
> As both are defined using a constant pattern, I expected none of them
> should require the type of the argument to be instance of Eq.
>
> Romildo
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120410/f0186337/attachment-0001.htm>

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

Message: 7
Date: Tue, 10 Apr 2012 17:30:37 -0400
From: Mike Meyer <[email protected]>
Subject: Re: [Haskell-beginners] Type of function with constant
        pattern
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII

On Tue, 10 Apr 2012 16:57:38 -0300
[email protected] wrote:

> Hello.
> 
> Given the following function definitions
> 
>    f 0 = True
> 
>    g False = True
> 
> ghc infers the following types for the functions:
> 
>    f :: (Eq a, Num a) => a -> Bool
>    g :: Bool -> Bool
> 
> Why f has "Eq a" in the context in ts type, and g does not?

Bool is an instance of Eq, so there's no need to say that your
(non-existent) type variable has that constraint.

Using a numeric constants means you get a type variable with the Num
constraint. Since Num doesn't imply Eq, that constraint is (as Tim
pointed out) required so the guard can be checked.

        <mike
-- 
Mike Meyer <[email protected]>             http://www.mired.org/
Independent Software developer/SCM consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org



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

Message: 8
Date: Tue, 10 Apr 2012 20:26:37 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Type of function with constant
        pattern
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Tue, Apr 10, 2012 at 05:30:37PM -0400, Mike Meyer wrote:
> On Tue, 10 Apr 2012 16:57:38 -0300
> [email protected] wrote:
> 
> > Hello.
> > 
> > Given the following function definitions
> > 
> >    f 0 = True
> > 
> >    g False = True
> > 
> > ghc infers the following types for the functions:
> > 
> >    f :: (Eq a, Num a) => a -> Bool
> >    g :: Bool -> Bool
> > 
> > Why f has "Eq a" in the context in ts type, and g does not?
> 
> Bool is an instance of Eq, so there's no need to say that your
> (non-existent) type variable has that constraint.

This is not really the reason; no instance of Eq for Bool is required.
Note that you can even pattern-match like this on a type which is not
an instance of Eq:

  data Foo = Bar | Baz

  f Bar = True

Here the type of f is inferred as  Foo -> Bool, even though there is
no instance of Eq for Foo.  Pattern-matching is more fundamental than
equality testing.

The reason Eq is needed for the definition  f 0 = True   is that 0 is
not actually a constructor.  Numeric literal patterns are provided as
a convenience, but they desugar into a guard of the form

  f x | x == 0 = ...

Hence, an instance of Eq is needed.

-Brent



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

Message: 9
Date: Tue, 10 Apr 2012 21:40:43 -0300
From: [email protected]
Subject: Re: [Haskell-beginners] Type of function with constant
        pattern
To: Mike Meyer <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Tue, Apr 10, 2012 at 05:30:37PM -0400, Mike Meyer wrote:
> On Tue, 10 Apr 2012 16:57:38 -0300
> [email protected] wrote:
> 
> > Hello.
> > 
> > Given the following function definitions
> > 
> >    f 0 = True
> > 
> >    g False = True
> > 
> > ghc infers the following types for the functions:
> > 
> >    f :: (Eq a, Num a) => a -> Bool
> >    g :: Bool -> Bool
> > 
> > Why f has "Eq a" in the context in ts type, and g does not?
> 
> Bool is an instance of Eq, so there's no need to say that your
> (non-existent) type variable has that constraint.
> 
> Using a numeric constants means you get a type variable with the Num
> constraint. Since Num doesn't imply Eq, that constraint is (as Tim
> pointed out) required so the guard can be checked.

Then consider the following type and function definitions:

   data T = A | B

   h A = True
   h B = False

The type T is not an instance of Eq. The inferred type by ghc for the
function h is

   h :: T -> Bool

which does not require T to be an instance of the Eq class.

Therefore pattern matching on the constant data constuctors A and B is
not related to the Eq class, which provides the equality function (==).

This example contradicts the explanation given above by Mike.

And the question remains: why pattern matching on numeric constants,
differently from other constants, requires the Eq class?

Romildo



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

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 46, Issue 12
*****************************************

Reply via email to