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: Type of function with constant pattern ([email protected])
2. Re: PutStrLn (Brandon Allbery)
3. Re: Type of function with constant pattern (Brandon Allbery)
----------------------------------------------------------------------
Message: 1
Date: Tue, 10 Apr 2012 21:53:05 -0300
From: [email protected]
Subject: Re: [Haskell-beginners] Type of function with constant
pattern
To: Tim Perry <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Tue, Apr 10, 2012 at 02:16:15PM -0700, Tim Perry wrote:
> 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.
I think you are using the wrong terms. The given examples does not make
any use of guards. Guards are boolean expressions attached to the right
side of equations. They are used to select one from many possible right
sides of the equation: the first one whose guard evaluates to True is
chosen. (Of course the patterns used as formal parameters should first
match the actual arguments.)
For instance
sign x | x < 0 = -1
| x == 0 = 0
| x > 0 = 1
defines a function using an equation with three guards.
I think pattern matching with constant data construtors is not related
to the (==) or (/=) methods defined in class Eq. At least I was not able
to find that out on the documentation.
For this reason I am not understand why Eq is used when pattern matching
with numeric constants, as shown in the original post.
So, Tim's explanation is not making sense to me.
]
Romildo
> On Tue, Apr 10, 2012 at 12:57 PM, <[email protected]> wrote:
>
> > 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.
------------------------------
Message: 2
Date: Tue, 10 Apr 2012 22:01:11 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] PutStrLn
To: Pierre Michallet <[email protected]>
Cc: beginners haskell <[email protected]>
Message-ID:
<CAKFCL4V5TL3DpaA64a_FB1JXvs_e477ojFPm-NK=viydrax...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Tue, Apr 10, 2012 at 11:57, Pierre Michallet <[email protected]> wrote:
> **
> 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
>
putStrLn just emits text; your terminal emulator decides what font and
spacing will be used.
What are you really trying to do?
--
brandon s allbery [email protected]
wandering unix systems administrator (available) (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120410/dc1185c7/attachment-0001.htm>
------------------------------
Message: 3
Date: Tue, 10 Apr 2012 22:07:08 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] Type of function with constant
pattern
To: [email protected]
Cc: [email protected]
Message-ID:
<cakfcl4w5zkslfjvczt5sut5ckadia5cxxxs44vsp4bs2kfk...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Tue, Apr 10, 2012 at 20:53, <[email protected]> wrote:
> On Tue, Apr 10, 2012 at 02:16:15PM -0700, Tim Perry wrote:
> > 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.
>
> I think you are using the wrong terms. The given examples does not make
> any use of guards. Guards are boolean expressions attached to the right
>
It is using guards; you don't see them, because it's quietly translated by
the compiler in the same way that `do` blocks are translated into
applications of (>>=) and (>>) operators.
The reason for this is that numeric literals aren't actually literals; they
are applications of the `fromInteger` function. This is true even in
patterns; therefore they can't actually be matched as patterns but are
translated into guards.
--
brandon s allbery [email protected]
wandering unix systems administrator (available) (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120410/bb5ef0cd/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 46, Issue 13
*****************************************