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. Average of numeric list (Nadav Chernin)
2. Re: Average of numeric list (Daniel Fischer)
3. Re: Average of numeric list (Elvio Rogelio Toccalino)
4. how to make something Typeable, for Data.Dynamic? (Rob Nikander)
5. Looking for some pro bono haskell work (Patrick Lynch)
6. Re: Looking for some pro bono haskell work (aditya siram)
7. Re: how to make something Typeable, for Data.Dynamic?
(Edward Z. Yang)
8. Word suggestion package? (Tom Murphy)
9. Re: Average of numeric list (Nadav Chernin)
----------------------------------------------------------------------
Message: 1
Date: Mon, 4 Apr 2011 18:15:20 +0300
From: Nadav Chernin <[email protected]>
Subject: [Haskell-beginners] Average of numeric list
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hello,
I tried to write function mean - average of numeric list.
mean::(Fractional a)=>[a]->a
mean a = (realToFrac (sum a)) / (realToFrac (length a))
But error occures:
Could not deduce (Real a) from the context (Fractional b)
arising from a use of `realToFrac'
To correct this function, i rewrite this function:
mean::(Real a, Fractional a)=>[a]->b
mean a = (realToFrac (sum a)) / (realToFrac (length a))
Is there most simple way to write this function?
Thanks, Nadav
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110404/71c2c51a/attachment-0001.htm>
------------------------------
Message: 2
Date: Mon, 4 Apr 2011 17:46:11 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Average of numeric list
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="utf-8"
On Monday 04 April 2011 17:15:20, Nadav Chernin wrote:
> Hello,
>
> I tried to write function mean - average of numeric list.
>
> mean::(Fractional a)=>[a]->a
> mean a = (realToFrac (sum a)) / (realToFrac (length a))
>
> But error occures:
>
> Could not deduce (Real a) from the context (Fractional b)
> arising from a use of `realToFrac'
> To correct this function, i rewrite this function:
>
> mean::(Real a, Fractional a)=>[a]->b
> mean a = (realToFrac (sum a)) / (realToFrac (length a))
>
> Is there most simple way to write this function?
mean :: Fractional a => [a] -> a
mean xs = sum xs / fromIntegral (length xs)
Note however, that that's not a particularly efficient way to calculate the
mean, since the compiler isn't smart enough to transform it into a loop
traversing the list once (so allowing it to be garbage collected as it is
consumed and the computation to run in constant space) and keeping the
accumulators evaluated.
>
> Thanks, Nadav
------------------------------
Message: 3
Date: Mon, 4 Apr 2011 13:23:14 -0300
From: Elvio Rogelio Toccalino <[email protected]>
Subject: Re: [Haskell-beginners] Average of numeric list
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
2011/4/4 Daniel Fischer <[email protected]>
> On Monday 04 April 2011 17:15:20, Nadav Chernin wrote:
> > Hello,
> >
> > I tried to write function mean - average of numeric list.
> >
> > mean::(Fractional a)=>[a]->a
> > mean a = (realToFrac (sum a)) / (realToFrac (length a))
> >
> > But error occures:
> >
> > Could not deduce (Real a) from the context (Fractional b)
> > arising from a use of `realToFrac'
> > To correct this function, i rewrite this function:
> >
> > mean::(Real a, Fractional a)=>[a]->b
> > mean a = (realToFrac (sum a)) / (realToFrac (length a))
> >
> > Is there most simple way to write this function?
>
For simple functions it is often revealing to define it in ghci and only
then ask its type:
-- your version:
Prelude> let m2 as = (realToFrac $ sum as) / (realToFrac $ length as)
Prelude> :t m2
m2 :: (Real a, Fractional b) => [a] -> b
-- Daniel's version:
Prelude> let m1 as = sum as / (fromIntegral $ length as)
Prelude> :t m1
m1 :: (Fractional b) => [b] -> b
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110404/3f856d8a/attachment-0001.htm>
------------------------------
Message: 4
Date: Mon, 4 Apr 2011 17:16:57 -0400
From: Rob Nikander <[email protected]>
Subject: [Haskell-beginners] how to make something Typeable, for
Data.Dynamic?
To: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
Can someone show me a code snippet that would make a simple record
type Typeable so I can wrap one in a Data.Dynamic? I'm looking at the
haddock docs and I don't see how to do it. I know to define "typeOf
:: MyRecord -> TypeRep". But how to make a TypeRep?
thanks,
Rob
------------------------------
Message: 5
Date: Mon, 04 Apr 2011 17:17:13 -0400
From: "Patrick Lynch" <[email protected]>
Subject: [Haskell-beginners] Looking for some pro bono haskell work
To: <[email protected]>
Message-ID: <1E892E4EA0144F41BB64636C4CB4266D@UserPC>
Content-Type: text/plain; charset="utf-8"
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110404/f1edbfde/attachment-0001.htm>
------------------------------
Message: 6
Date: Mon, 4 Apr 2011 16:19:57 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] Looking for some pro bono haskell
work
To: Patrick Lynch <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
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: 7
Date: Mon, 04 Apr 2011 17:22:15 -0400
From: "Edward Z. Yang" <[email protected]>
Subject: Re: [Haskell-beginners] how to make something Typeable, for
Data.Dynamic?
To: Rob Nikander <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <1301952090-sup-1081@ezyang>
Content-Type: text/plain; charset=UTF-8
You need the language extension DeriveDataTypeable,
and then you just add
deriving (Typeable)
to the end of your data declaration.
Cheers,
Edward
Excerpts from Rob Nikander's message of Mon Apr 04 17:16:57 -0400 2011:
> Hi,
>
> Can someone show me a code snippet that would make a simple record
> type Typeable so I can wrap one in a Data.Dynamic? I'm looking at the
> haddock docs and I don't see how to do it. I know to define "typeOf
> :: MyRecord -> TypeRep". But how to make a TypeRep?
>
> thanks,
> Rob
>
------------------------------
Message: 8
Date: Mon, 4 Apr 2011 19:35:59 -0400
From: Tom Murphy <[email protected]>
Subject: [Haskell-beginners] Word suggestion package?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi,
Can anyone point me towards a package for a UI element, which gives
options for word completion?
In other words, I type "Ha" into a text box, and it gives me choices to
fill the text box with either "Haskore," "Haskell," or "Hayoo."
Hoogle has a function "suggestions," which returns a list of
suggestions, and Leksah has a tool within its code editor with functionality
similar to what I'm looking for, but I'm looking for a package which has
this as a UI element.
Thanks for your time!
Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110404/10a27edd/attachment-0001.htm>
------------------------------
Message: 9
Date: Tue, 5 Apr 2011 11:38:37 +0300
From: Nadav Chernin <[email protected]>
Subject: Re: [Haskell-beginners] Average of numeric list
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
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
On Mon, Apr 4, 2011 at 7:23 PM, Elvio Rogelio Toccalino <
[email protected]> wrote:
>
>
> 2011/4/4 Daniel Fischer <[email protected]>
>
>> On Monday 04 April 2011 17:15:20, Nadav Chernin wrote:
>> > Hello,
>> >
>> > I tried to write function mean - average of numeric list.
>> >
>> > mean::(Fractional a)=>[a]->a
>> > mean a = (realToFrac (sum a)) / (realToFrac (length a))
>> >
>> > But error occures:
>> >
>> > Could not deduce (Real a) from the context (Fractional b)
>> > arising from a use of `realToFrac'
>> > To correct this function, i rewrite this function:
>> >
>> > mean::(Real a, Fractional a)=>[a]->b
>> > mean a = (realToFrac (sum a)) / (realToFrac (length a))
>> >
>> > Is there most simple way to write this function?
>>
>
> For simple functions it is often revealing to define it in ghci and only
> then ask its type:
>
> -- your version:
> Prelude> let m2 as = (realToFrac $ sum as) / (realToFrac $ length as)
> Prelude> :t m2
> m2 :: (Real a, Fractional b) => [a] -> b
>
> -- Daniel's version:
> Prelude> let m1 as = sum as / (fromIntegral $ length as)
> Prelude> :t m1
> m1 :: (Fractional b) => [b] -> b
>
>
> _______________________________________________
> 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/20110405/fd0830da/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 34, Issue 6
****************************************