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.  Algebraic types, shared parameters,      pattern matching
      (Christopher Howard)
   2. Re:  Algebraic types, shared parameters,  pattern matching
      (Karl Voelker)
   3. Re:  Netwire loop (Ertugrul S?ylemez)


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

Message: 1
Date: Wed, 31 Oct 2012 18:36:54 -0800
From: Christopher Howard <[email protected]>
Subject: [Haskell-beginners] Algebraic types, shared parameters,
        pattern matching
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

I noticed that with algebraic types I can do something like so:

code
--------
data Projectile = Bullet { range :: Double }
                  | Missile { range :: Double }
                  | Torpedo { range :: Double }

f p = let r = range p in
      ...whatever...

--------

(This is interesting in and of itself, as I don't in this case have to
do pattern matching for each constructor. Also, apparently not all the
constructors actually need to have a "range" selector for the program to
compile!)

However, what if I wanted to make the same function f (again, without
multiple lines of pattern matching) but using a "simpler" data type like so:

code:
--------
type Range = Double

data Projectile = Bullet Range | Missile Range | Torpedo Range
--------

My first try was

code
--------
f (_ r) = ...
--------

But that doesn't work.

-- 
frigidcode.com
indicium.us

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 551 bytes
Desc: OpenPGP digital signature
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20121031/ea6fcfc6/attachment-0001.pgp>

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

Message: 2
Date: Thu, 1 Nov 2012 00:05:45 -0700
From: Karl Voelker <[email protected]>
Subject: Re: [Haskell-beginners] Algebraic types, shared parameters,
        pattern matching
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID:
        <CAFfow0xZFGCMSUuqdmMyFQ=DML7e-=jbgi4e8ul_jbjnucg...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

On Wed, Oct 31, 2012 at 7:36 PM, Christopher Howard
<[email protected]> wrote:
> (This is interesting in and of itself, as I don't in this case have to
> do pattern matching for each constructor. Also, apparently not all the
> constructors actually need to have a "range" selector for the program to
> compile!)

I would avoid using this "feature" of the language, because non-total
functions are a hassle.

> code:
> --------
> type Range = Double
>
> data Projectile = Bullet Range | Missile Range | Torpedo Range
>
> f (_ r) = ...
> --------

Nope, you can't do that. But you can do this:

data ProjectileType = Bullet | Missile | Torpedo

data Projectile = Projectile ProjectileType Range

f (Projectile _ r) = ...

-Karl



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

Message: 3
Date: Thu, 1 Nov 2012 11:15:10 +0100
From: Ertugrul S?ylemez <[email protected]>
Subject: Re: [Haskell-beginners] Netwire loop
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

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

> Hi,
> When testing this netwire sample program
>
> [...]
>
> mainWire :: WireP () Double
> mainWire = proc i -> do
>   rec
>     value <- integral_ 0.0 -< oldValue
>     oldValue <- delay 1.0 -< value
>   returnA -< value
>
> [...]
>
> I get this output:
> NetwireTest: <<loop>>
>
> But there should be not infinite loop, should there?

That was a bug in the ArrowLoop implementation.  It's fixed now in
version 4.0.1.  Thanks for reporting.


Greets,
Ertugrul

-- 
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.
-------------- 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/20121101/6c1d02d4/attachment-0001.pgp>

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

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


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

Reply via email to