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: Average of numeric list (Daniel Fischer)
2. Re: Average of numeric list (Nadav Chernin)
3. Re: Looking for some pro bono haskell work (Patrick Lynch)
4. Re: Looking for some pro bono haskell work (Patrick Lynch)
5. Re: Looking for some pro bono haskell work (Bryce Verdier)
----------------------------------------------------------------------
Message: 1
Date: Tue, 5 Apr 2011 13:56:50 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Average of numeric list
To: Nadav Chernin <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="utf-8"
On Tuesday 05 April 2011 11:57:32, Nadav Chernin wrote:
> How can i know when casting of types maked by compiler and when
> programmer must to do it?
Generally, there are no implicit type conversions in Haskell, so you always
have to do it explicitly.
An exception are numeric literals, an integer literal (in source code or at
the ghci/hugs prompt) stands for
fromInteger (integerValueParsedFromLiteral)
-- fromInteger :: Num n => Integer -> n
and a floating-point literal (like 1.234e56) stands for
fromRational (rationalParsedFromLiteral)
-- fromRational :: Fractional a => Rational -> a
Unless my memory fails, those are the only implicit conversions the
language report specifies. In GHC (I don't know which other compilers, if
any, implement it), you can turn on the OverloadedStrings language
extension to get overloaded string literals (for instances of the IsString
class), so "this" could be a String , a ByteString or a Text (and some
others), provided the relevant modules are in scope.
Other language extensions providing compiler-generated conversions may
exist (now or in future), but I'm not aware of any.
A different, but not unrelated, issue is polymorphism (with type
inference).
When you use polymorphic expressions - like [], Nothing, (return True),
(realToFrac pi) - the compiler uses the context in which the expression
occurs to infer the type at which the expression is used.
If that doesn't yield a monomorphic type, under some circumstances the type
gets defaulted
(http://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-790004.3.4),
or you get a compile error since the compiler couldn't determine what to
do.
If you don't use any conversion functions,
mean0 xs = sum xs / length xs,
the compiler infers
- xs :: Num n => [n]
(from sum :: Num n => [n] -> n)
- sum xs :: Fractional f => f
(from (/) :: Fractional f => f -> f -> f)
- combining those : xs :: (Num c, Fractional c) => [c]
Num is a superclass of Fractional, so the constraint can be simplified,
giving
- xs :: Fractional c => [c]
Then (length xs :: Int), inferred from (length :: [a] -> Int), as the
second argument of (/) forces c = Int, giving the type
mean0 :: Fractional Int => [Int] -> Int
Normally you don't have a Fractional instance for Int in scope, so the
compilation would fail with a "No instance ..." error. If you had such an
instance in scope, the superfluous because fulfilled constraint would be
removed, giving mean0 :: [Int] -> Int.
Now, inserting the fromIntegral conversion in the second argument,
mean1 xs = sum xs / fromIntegral (length xs)
the first part remains unchanged, resulting in
xs :: Fractional f => [f],
then (sum xs :: f -- for that same, as yet undetermined Fractional type f)
and fromIntegral's result must have the same type f.
Since
fromIntegral :: (Integral i, Num n) => i -> n,
length xs :: Int, Int is an instance of Integral and Num is more general
than Fractional, fromIntegral (length xs) can have that type, enabling the
compiler to pick the right fromIntegral as soon as it knows f. Overall,
mean1 :: Fractional f => [f] -> f,
the type f can be determined by passing a list of specific type or using
the result at specific type.
Inserting a conversion for the sum, say realToFrac,
mean2 xs = realToFrac (sum xs) / fromIntegral (length xs)
changes the constraint on the type of xs' elements, now it need no longer
be a suitable argument for (/) [Fractional], but for realToFrac [Real].
(realToFrac $ sum xs) has to be the same Fractional type as
(fromIntegral $ length xs) but can be any Fractional type, giving
mean2 :: (Real r, Fractional f) => [r] -> f
r can only be determined by passing an argument of specific type, f only by
using the result at a specific type.
>
> On Tue, Apr 5, 2011 at 12:14 PM, Daniel Fischer <
>
> [email protected]> wrote:
> > On Tuesday 05 April 2011 10:38:37, Nadav Chernin wrote:
> > > Why only "length as" we must to cast? Why "sum as", that have type
> > > Integer can be used in (/).
> > >
> > > :t (/)
> > >
> > > (/) :: (Fractional a) => a -> a -> a
> >
> > No, sum as has the type of as's elements,
> >
> > sum :: Num a => [a] -> a
> >
> > So the use of (/) refines the constraint from (Num a) to (Fractional
> > a). if you want it to work on Integers too,
> > you'd get
> >
> > mean :: (Real a, Fractional b) => [a] -> b
> > mean xs = realToFrac (sum xs) / (fromIntegral $ length xs)
------------------------------
Message: 2
Date: Tue, 5 Apr 2011 15:08:59 +0300
From: Nadav Chernin <[email protected]>
Subject: Re: [Haskell-beginners] Average of numeric list
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Thank you very much
Nadav Chernin
On Tue, Apr 5, 2011 at 2:56 PM, Daniel Fischer <
[email protected]> wrote:
> On Tuesday 05 April 2011 11:57:32, Nadav Chernin wrote:
> > How can i know when casting of types maked by compiler and when
> > programmer must to do it?
>
> Generally, there are no implicit type conversions in Haskell, so you always
> have to do it explicitly.
> An exception are numeric literals, an integer literal (in source code or at
> the ghci/hugs prompt) stands for
>
> fromInteger (integerValueParsedFromLiteral)
> -- fromInteger :: Num n => Integer -> n
>
> and a floating-point literal (like 1.234e56) stands for
>
> fromRational (rationalParsedFromLiteral)
> -- fromRational :: Fractional a => Rational -> a
>
> Unless my memory fails, those are the only implicit conversions the
> language report specifies. In GHC (I don't know which other compilers, if
> any, implement it), you can turn on the OverloadedStrings language
> extension to get overloaded string literals (for instances of the IsString
> class), so "this" could be a String , a ByteString or a Text (and some
> others), provided the relevant modules are in scope.
>
> Other language extensions providing compiler-generated conversions may
> exist (now or in future), but I'm not aware of any.
>
> A different, but not unrelated, issue is polymorphism (with type
> inference).
> When you use polymorphic expressions - like [], Nothing, (return True),
> (realToFrac pi) - the compiler uses the context in which the expression
> occurs to infer the type at which the expression is used.
> If that doesn't yield a monomorphic type, under some circumstances the type
> gets defaulted
> (
> http://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-790004.3.4
> ),
> or you get a compile error since the compiler couldn't determine what to
> do.
>
> If you don't use any conversion functions,
>
> mean0 xs = sum xs / length xs,
>
> the compiler infers
>
> - xs :: Num n => [n]
> (from sum :: Num n => [n] -> n)
> - sum xs :: Fractional f => f
> (from (/) :: Fractional f => f -> f -> f)
> - combining those : xs :: (Num c, Fractional c) => [c]
> Num is a superclass of Fractional, so the constraint can be simplified,
> giving
> - xs :: Fractional c => [c]
>
> Then (length xs :: Int), inferred from (length :: [a] -> Int), as the
> second argument of (/) forces c = Int, giving the type
>
> mean0 :: Fractional Int => [Int] -> Int
>
> Normally you don't have a Fractional instance for Int in scope, so the
> compilation would fail with a "No instance ..." error. If you had such an
> instance in scope, the superfluous because fulfilled constraint would be
> removed, giving mean0 :: [Int] -> Int.
>
> Now, inserting the fromIntegral conversion in the second argument,
>
> mean1 xs = sum xs / fromIntegral (length xs)
>
> the first part remains unchanged, resulting in
> xs :: Fractional f => [f],
>
> then (sum xs :: f -- for that same, as yet undetermined Fractional type f)
> and fromIntegral's result must have the same type f.
> Since
>
> fromIntegral :: (Integral i, Num n) => i -> n,
>
> length xs :: Int, Int is an instance of Integral and Num is more general
> than Fractional, fromIntegral (length xs) can have that type, enabling the
> compiler to pick the right fromIntegral as soon as it knows f. Overall,
>
> mean1 :: Fractional f => [f] -> f,
>
> the type f can be determined by passing a list of specific type or using
> the result at specific type.
>
> Inserting a conversion for the sum, say realToFrac,
>
> mean2 xs = realToFrac (sum xs) / fromIntegral (length xs)
>
> changes the constraint on the type of xs' elements, now it need no longer
> be a suitable argument for (/) [Fractional], but for realToFrac [Real].
> (realToFrac $ sum xs) has to be the same Fractional type as
> (fromIntegral $ length xs) but can be any Fractional type, giving
>
> mean2 :: (Real r, Fractional f) => [r] -> f
>
> r can only be determined by passing an argument of specific type, f only by
> using the result at a specific type.
>
> >
> > On Tue, Apr 5, 2011 at 12:14 PM, Daniel Fischer <
> >
> > [email protected]> wrote:
> > > On Tuesday 05 April 2011 10:38:37, Nadav Chernin wrote:
> > > > Why only "length as" we must to cast? Why "sum as", that have type
> > > > Integer can be used in (/).
> > > >
> > > > :t (/)
> > > >
> > > > (/) :: (Fractional a) => a -> a -> a
> > >
> > > No, sum as has the type of as's elements,
> > >
> > > sum :: Num a => [a] -> a
> > >
> > > So the use of (/) refines the constraint from (Num a) to (Fractional
> > > a). if you want it to work on Integers too,
> > > you'd get
> > >
> > > mean :: (Real a, Fractional b) => [a] -> b
> > > mean xs = realToFrac (sum xs) / (fromIntegral $ length xs)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110405/68e99cc3/attachment-0001.htm>
------------------------------
Message: 3
Date: Tue, 05 Apr 2011 09:45:12 -0400
From: "Patrick Lynch" <[email protected]>
Subject: Re: [Haskell-beginners] Looking for some pro bono haskell
work
To: "aditya siram" <[email protected]>
Cc: [email protected]
Message-ID: <B289CA9F43874FACA997D1829D6487CE@UserPC>
Content-Type: text/plain; format=flowed; charset=iso-8859-1;
reply-type=original
Good morning,
Thanks for the advice.
I sent an email to Zvon and volunteered to help them with the examples of
Haskell functions in their "Haskell Reference Page"
The projects that I envisage are:
- I tried to get TK installed but was unable to do so, if someone is
working this install, I would be willing to test it for them...
- If anyone is working on a web front-end to Haskell, I would be
willing to participate...
Good day
----- Original Message -----
From: "aditya siram" <[email protected]>
To: "Patrick Lynch" <[email protected]>
Cc: <[email protected]>
Sent: Monday, April 04, 2011 5:19 PM
Subject: Re: [Haskell-beginners] Looking for some pro bono haskell work
>I would pick a project and contribute a patch to it, or start one of your
>own.
> -deech
>
> On Mon, Apr 4, 2011 at 4:17 PM, Patrick Lynch <[email protected]>
> wrote:
>> Good afternoon,
>> I've read all the books and am looking for some pro bono Haskell
>> Development
>> work...
>> If you have some, please email me...
>> Thanks
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
------------------------------
Message: 4
Date: Tue, 05 Apr 2011 10:04:19 -0400
From: "Patrick Lynch" <[email protected]>
Subject: Re: [Haskell-beginners] Looking for some pro bono haskell
work
To: "aditya siram" <[email protected]>
Cc: [email protected]
Message-ID: <4E9C4238801F45C99253CEB0704B2568@UserPC>
Content-Type: text/plain; format=flowed; charset=iso-8859-1;
reply-type=response
...one more project...
I tried to understand Category Theory but was unable to do so...
I tried reading three books in regard to it and can understand the
definition of Category...but couldn't follow any of these books past the
first chapter and was unable to do any of the exercises in them...
However, I did see a few links that 'graphically' showed a Category and
another that showed some categories and how they were implemented in
Haskell - these made the most sense to me...
Since categories are the basis for Functors, Monoids and Monads - which are
extensively used in Haskell and implicitly used, I think, in Linq - I would
be very willing to participate in a project that showed categories and how
they are implemented in Haskell...
Just a thought...
Ps
I am an independent software consultant [been doing it for 30+ years].
I did a market evaluation of Haskell and Linq and found the following:
- there are page after page of Ling/C# jobs...
- I only saw 1 Haskell job...
It 'begs the question': is some commercial organization going to implement
Haskell as a product [I don't think it will be Microsoft, since they have
introduced F#]...
----- Original Message -----
From: "Patrick Lynch" <[email protected]>
To: "aditya siram" <[email protected]>
Cc: <[email protected]>
Sent: Tuesday, April 05, 2011 9:45 AM
Subject: Re: [Haskell-beginners] Looking for some pro bono haskell work
> Good morning,
> Thanks for the advice.
> I sent an email to Zvon and volunteered to help them with the examples of
> Haskell functions in their "Haskell Reference Page"
> The projects that I envisage are:
> - I tried to get TK installed but was unable to do so, if someone is
> working this install, I would be willing to test it for them...
> - If anyone is working on a web front-end to Haskell, I would be
> willing to participate...
> Good day
>
> ----- Original Message -----
> From: "aditya siram" <[email protected]>
> To: "Patrick Lynch" <[email protected]>
> Cc: <[email protected]>
> Sent: Monday, April 04, 2011 5:19 PM
> Subject: Re: [Haskell-beginners] Looking for some pro bono haskell work
>
>
>>I would pick a project and contribute a patch to it, or start one of your
>>own.
>> -deech
>>
>> On Mon, Apr 4, 2011 at 4:17 PM, Patrick Lynch <[email protected]>
>> wrote:
>>> Good afternoon,
>>> I've read all the books and am looking for some pro bono Haskell
>>> Development
>>> work...
>>> If you have some, please email me...
>>> Thanks
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>>
>>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 5
Date: Tue, 05 Apr 2011 08:45:49 -0700
From: Bryce Verdier <[email protected]>
Subject: Re: [Haskell-beginners] Looking for some pro bono haskell
work
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Patrick,
Since you are interested in helping a haskell based web front-end
project, have you thought about contacting the Yesod project?
Bryce
On 04/05/2011 07:04 AM, Patrick Lynch wrote:
> ...one more project...
>
> I tried to understand Category Theory but was unable to do so...
> I tried reading three books in regard to it and can understand the
> definition of Category...but couldn't follow any of these books past
> the first chapter and was unable to do any of the exercises in them...
> However, I did see a few links that 'graphically' showed a Category
> and another that showed some categories and how they were implemented
> in Haskell - these made the most sense to me...
> Since categories are the basis for Functors, Monoids and Monads -
> which are extensively used in Haskell and implicitly used, I think, in
> Linq - I would be very willing to participate in a project that showed
> categories and how they are implemented in Haskell...
>
> Just a thought...
>
> Ps
> I am an independent software consultant [been doing it for 30+ years].
> I did a market evaluation of Haskell and Linq and found the following:
> - there are page after page of Ling/C# jobs...
> - I only saw 1 Haskell job...
> It 'begs the question': is some commercial organization going to
> implement Haskell as a product [I don't think it will be Microsoft,
> since they have introduced F#]...
>
> ----- Original Message ----- From: "Patrick Lynch"
> <[email protected]>
> To: "aditya siram" <[email protected]>
> Cc: <[email protected]>
> Sent: Tuesday, April 05, 2011 9:45 AM
> Subject: Re: [Haskell-beginners] Looking for some pro bono haskell work
>
>
>> Good morning,
>> Thanks for the advice.
>> I sent an email to Zvon and volunteered to help them with the
>> examples of Haskell functions in their "Haskell Reference Page"
>> The projects that I envisage are:
>> - I tried to get TK installed but was unable to do so, if someone
>> is working this install, I would be willing to test it for them...
>> - If anyone is working on a web front-end to Haskell, I would be
>> willing to participate...
>> Good day
>>
>> ----- Original Message ----- From: "aditya siram"
>> <[email protected]>
>> To: "Patrick Lynch" <[email protected]>
>> Cc: <[email protected]>
>> Sent: Monday, April 04, 2011 5:19 PM
>> Subject: Re: [Haskell-beginners] Looking for some pro bono haskell work
>>
>>
>>> I would pick a project and contribute a patch to it, or start one of
>>> your own.
>>> -deech
>>>
>>> On Mon, Apr 4, 2011 at 4:17 PM, Patrick Lynch
>>> <[email protected]> wrote:
>>>> Good afternoon,
>>>> I've read all the books and am looking for some pro bono Haskell
>>>> Development
>>>> work...
>>>> If you have some, please email me...
>>>> Thanks
>>>> _______________________________________________
>>>> Beginners mailing list
>>>> [email protected]
>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>
>>>>
>>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 34, Issue 8
****************************************