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. list range (Stanis?aw Findeisen)
2. Re: list range (Henry Lockyer)
3. Re: list range (Henry Lockyer)
4. Re: list range (Brent Yorgey)
5. Re: list range (Jos? Romildo Malaquias)
6. Re: list range (Henry Lockyer)
7. Re: list range (Mike Meyer)
8. The numeric type stack (Mike Meyer)
9. Re: The numeric type stack (Antoine Latter)
10. Re: The numeric type stack (Mike Meyer)
----------------------------------------------------------------------
Message: 1
Date: Wed, 28 Dec 2011 19:51:35 +0100
From: Stanis?aw Findeisen <[email protected]>
Subject: [Haskell-beginners] list range
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
Hi
Is list range (for example: [1..10]) a language construct or a function?
What type does it have?
--
This e-mail address is invalid, see:
http://people.eisenbits.com/~stf/public-email-note.html .
OpenPGP: E3D9 C030 88F5 D254 434C 6683 17DD 22A0 8A3B 5CC0
------------------------------
Message: 2
Date: Wed, 28 Dec 2011 19:05:02 +0000
From: Henry Lockyer <[email protected]>
Subject: Re: [Haskell-beginners] list range
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
I'm a beginner so beware, but I believe [1..10] is a VALUE (it is not a
function from something to something else).
It's type is essentially 'list of numeric' but because you used "..." to
express a range of values it also has to be of
type 'Enum' as well as numeric.
If you have GHCI installed, then I recommend using the ":t" command to explore
the types of Haskell expressions.
/ Henry
On 28 Dec 2011, at 18:51, Stanis?aw Findeisen wrote:
> Hi
>
> Is list range (for example: [1..10]) a language construct or a function?
> What type does it have?
>
> --
> This e-mail address is invalid, see:
> http://people.eisenbits.com/~stf/public-email-note.html .
>
> OpenPGP: E3D9 C030 88F5 D254 434C 6683 17DD 22A0 8A3B 5CC0
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 3
Date: Wed, 28 Dec 2011 19:08:08 +0000
From: Henry Lockyer <[email protected]>
Subject: Re: [Haskell-beginners] list range
To: Henry Lockyer <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Sorry, should have read your question a second time instead of posting a quick
reply ;-)
I think it is syntactic sugar..
On 28 Dec 2011, at 19:05, Henry Lockyer wrote:
> I'm a beginner so beware, but I believe [1..10] is a VALUE (it is not a
> function from something to something else).
> It's type is essentially 'list of numeric' but because you used "..." to
> express a range of values it also has to be of
> type 'Enum' as well as numeric.
> If you have GHCI installed, then I recommend using the ":t" command to
> explore the types of Haskell expressions.
> / Henry
>
> On 28 Dec 2011, at 18:51, Stanis?aw Findeisen wrote:
>
>> Hi
>>
>> Is list range (for example: [1..10]) a language construct or a function?
>> What type does it have?
>>
>> --
>> This e-mail address is invalid, see:
>> http://people.eisenbits.com/~stf/public-email-note.html .
>>
>> OpenPGP: E3D9 C030 88F5 D254 434C 6683 17DD 22A0 8A3B 5CC0
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 4
Date: Wed, 28 Dec 2011 14:32:01 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] list range
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
On Wed, Dec 28, 2011 at 07:51:35PM +0100, Stanis?aw Findeisen wrote:
> Hi
>
> Is list range (for example: [1..10]) a language construct or a function?
> What type does it have?
[a .. b] is syntactic sugar which is translated into a call to the
function 'enumFromTo':
Prelude> [1 .. 10]
[1,2,3,4,5,6,7,8,9,10]
Prelude> enumFromTo 1 10
[1,2,3,4,5,6,7,8,9,10]
-Brent
------------------------------
Message: 5
Date: Wed, 28 Dec 2011 17:37:03 -0200
From: Jos? Romildo Malaquias <[email protected]>
Subject: Re: [Haskell-beginners] list range
To: Stanis?aw Findeisen <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
On Wed, Dec 28, 2011 at 07:51:35PM +0100, Stanis?aw Findeisen wrote:
> Hi
>
> Is list range (for example: [1..10]) a language construct or a function?
> What type does it have?
>
[ 1 .. 10 ]
is syntatic sugar for the function application
enumFromTo 1 10
enumFromTo is a method of the class Enum. Its type is
enumFromTo :: Enum a => a -> a -> [a]
There is also enumFrom, enumFromThen and enumFromThenTo.
Romildo
------------------------------
Message: 6
Date: Wed, 28 Dec 2011 19:37:42 +0000
From: Henry Lockyer <[email protected]>
Subject: Re: [Haskell-beginners] list range
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Hi again Stanislaw,
since I started digging in this hole..
Having just checked "enum" in the prelude there are a number of functions such
as "enumFrom", "enumFromThen", "enumFromTo" etc. that the list range notation
syntactic sugar is converted to.
/Henry
On 28 Dec 2011, at 19:08, Henry Lockyer wrote:
> Sorry, should have read your question a second time instead of posting a
> quick reply ;-)
> I think it is syntactic sugar..
>
> On 28 Dec 2011, at 19:05, Henry Lockyer wrote:
>
>> I'm a beginner so beware, but I believe [1..10] is a VALUE (it is not a
>> function from something to something else).
>> It's type is essentially 'list of numeric' but because you used "..." to
>> express a range of values it also has to be of
>> type 'Enum' as well as numeric.
>> If you have GHCI installed, then I recommend using the ":t" command to
>> explore the types of Haskell expressions.
>> / Henry
>>
>> On 28 Dec 2011, at 18:51, Stanis?aw Findeisen wrote:
>>
>>> Hi
>>>
>>> Is list range (for example: [1..10]) a language construct or a function?
>>> What type does it have?
>>>
>>> --
>>> This e-mail address is invalid, see:
>>> http://people.eisenbits.com/~stf/public-email-note.html .
>>>
>>> OpenPGP: E3D9 C030 88F5 D254 434C 6683 17DD 22A0 8A3B 5CC0
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
------------------------------
Message: 7
Date: Wed, 28 Dec 2011 12:19:25 -0800
From: Mike Meyer <[email protected]>
Subject: Re: [Haskell-beginners] list range
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
On Wed, 28 Dec 2011 19:08:08 +0000
Henry Lockyer <[email protected]> wrote:
> On 28 Dec 2011, at 19:05, Henry Lockyer wrote:
> Sorry, should have read your question a second time instead of posting a
> quick reply ;-)
> I think it is syntactic sugar..
Others say it's syntactic sugar, but your advice:
> > If you have GHCI installed, then I recommend using the ":t" command to
> > explore the types of Haskell expressions.
is still good, *and* can answer that question:
> >> Is list range (for example: [1..10]) a language construct or a function?
> >> What type does it have?
If it's a function, then :t will know about it, even in that odd
form if you wrap it in parens. For instance:
*Main> :t (+)
(+) :: Num a => a -> a -> a
even if it's a constructor, like:
*Main> :t ((,))
((,)) :: a -> b -> (a, b)
But trying the [..] notation, you get:
*Main Network.HTTP> :t ([..])
<interactive>:1:3: parse error on input `..'
I.e. - it's syntactic sugar to generate a value. If it were a
function, the type would be something like:
([..]) :: Enum a => a -> a -> [a]
<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: Wed, 28 Dec 2011 18:54:33 -0800
From: Mike Meyer <[email protected]>
Subject: [Haskell-beginners] The numeric type stack
To: beginners <[email protected]>
Message-ID:
<CAD=7U2B8_FZb=5ketjqo+jtgjncurx++cysg54szzs0s_32...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
While haskell's type system is usually a delight to work with.
However, every once and a while I need to do mixed mode programming in
spite of Kernighan and Plauger's advice, and wind up cursing the
numeric type stack. I was wondering it there was a writeup on it
somewhere? Preferably one aimed at practical programming. A chapter in
Real World Haskell would have been ideal, but it doesn't seem to
exist.
Thanks,
<mike
------------------------------
Message: 9
Date: Wed, 28 Dec 2011 22:23:12 -0600
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] The numeric type stack
To: Mike Meyer <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
<cakjsnqhphyf_0g+nmcwajexsy1lzqhrgov_nn22urmjy6p-...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
On Wed, Dec 28, 2011 at 8:54 PM, Mike Meyer <[email protected]> wrote:
> While haskell's type system is usually a delight to work with.
> However, every once and a while I need to do mixed mode programming in
> spite of Kernighan and Plauger's advice, and wind up cursing the
> numeric type stack. I was wondering it there was a writeup on it
> somewhere? Preferably one aimed at practical programming. A chapter in
> Real World Haskell would have been ideal, but it doesn't seem to
> exist.
>
For shear comprehensiveness, there's always the language report:
http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1350006.4
I don't know of anything that lays out and introduction with best
practices and common pitfalls.
Antoine
> ? Thanks,
> ? <mike
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 10
Date: Wed, 28 Dec 2011 21:33:23 -0800
From: Mike Meyer <[email protected]>
Subject: Re: [Haskell-beginners] The numeric type stack
To: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
On Wed, 28 Dec 2011 22:23:12 -0600
Antoine Latter <[email protected]> wrote:
> On Wed, Dec 28, 2011 at 8:54 PM, Mike Meyer <[email protected]> wrote:
> > While haskell's type system is usually a delight to work with.
> > However, every once and a while I need to do mixed mode programming in
> > spite of Kernighan and Plauger's advice, and wind up cursing the
> > numeric type stack. I was wondering it there was a writeup on it
> > somewhere? Preferably one aimed at practical programming. A chapter in
> > Real World Haskell would have been ideal, but it doesn't seem to
> > exist.
> For shear comprehensiveness, there's always the language report:
> http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1350006.4
Not to bad. Then again, I'm a long-time language lawyer, so others may
disagree.
> I don't know of anything that lays out and introduction with best
> practices and common pitfalls.
Given reading the report, and a little experimentation, I figured out
the problem I was having. I probably will in the future as well.
I wanted a percentage value rounded to the nearest integer. No
problem, it's just:
(%) a b = round $ 100 * a / b
And that works in ghci. However, it has the type
(%) :: (RealFrac a, Integral b) => a -> a -> b
Which means that the argument from length was of the wrong type for
this. And naturally, declaring the argument types that matched the
result from length caused type problems inside (%).
So, is there a reasonable way to get the value of two Integral types
divided by each other and rounded? How about one integral type and one
RealFrac? I know I can get it truncated towards either 0 or negative
infinity, but that's not what I want here.
Thanks,
<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
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 42, Issue 30
*****************************************