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: Constrained polymorphic functions as natural
transformations (Matt R)
2. Re: Constrained polymorphic functions as natural
transformations (Kim-Ee Yeoh)
3. Error with floats in implementation of Horner's method.
(Andrew Fleckenstein)
4. Re: Error with floats in implementation of Horner's method.
(Andrew Fleckenstein)
5. Re: Error with floats in implementation of Horner's method.
(Kim-Ee Yeoh)
6. Re: Error with floats in implementation of Horner's method.
(Andrew Fleckenstein)
----------------------------------------------------------------------
Message: 1
Date: Fri, 13 Dec 2013 15:25:03 +0000
From: Matt R <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Constrained polymorphic functions as
natural transformations
Message-ID:
<CA+ixoL=vks2yy2vrouewwwv7mfxy9zov5hosdt3fhqoa18c...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Hi Brent,
Many thanks for taking the time to have a look! Hope you might be able to
cope with some more amateurish fumbling as I try and expand my
understanding...
On 14 November 2013 13:59, Brent Yorgey <[email protected]> wrote:
> In general one must consider what are called
> *di*natural transformations. (I ought to write a blog post about
> this.)...but I thought I would mention it in case you want to look it up
> later.
Thanks -- dinatural transformations are probably a bit beyond my comfort
zone right now, but I'll add it to my list of things to look at.
Interesting to discover that not all polymorphic functions are natural
transformations. "fix" seems rather exotic -- are there any less unusual
examples?
Note that you can't always characterize a type class by a single
> function like this. For example, consider class Foo ... There is no way
> to pick functors f and g such that a Foo dictionary is
> equivalent to f a -> g a.
>
I was wondering why the following wouldn't do the trick?
sig :: Foo a => Either Int a -> Either a Int
sig (Left n) = Left (bar n)
sig (Right a) = Right (baz a)
> This doesn't really make sense. If a natural transformation
> consists of a family of arrows which all live in Hask_T,
In this case, I think the family of arrows lives in Hask -- we can
reinterpret our Hask endofunctors as instead being functors from Hask_T ->
Hask. Then there's no requirement on our constrained polymorphic functions
to commute with sig.
In your example function f, the two functors would be the identify functor
"Id" and a constant functor "K Foo", and naturality is just saying that,
for any function g: A -> B that satisfies show == show . f, then:
f = f . g
Which is clearly true for f.
Am I still barking up the wrong tree? Apologies if so, but it *feels* like
there should be something here, with the intuition that:
Functions that don't "inspect" their values ==> you can substitute values
without fundamentally affecting the action of the function ==> natural
transformations between Hask endofunctors.
Functions that don't inspect their values other than through a particular
interface T ==> you can substitute values without fundamentally affecting
the action of the function, providing your substitution is invisible
through the interface T ==> Natural transformations between functors Hask_T
-> Hask.
-- Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131213/14a92d18/attachment-0001.html>
------------------------------
Message: 2
Date: Sat, 14 Dec 2013 01:55:08 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Constrained polymorphic functions as
natural transformations
Message-ID:
<CAPY+ZdQLCMuanaqPicS=_h1lwtycdeqs5c_8vrkasyybhai...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Fri, Dec 13, 2013 at 10:25 PM, Matt R <[email protected]> wrote:
> Interesting to discover that not all polymorphic functions are natural
> transformations. "fix" seems rather exotic -- are there any less unusual
> examples?
None of the church numerals of type (a -> a) -> (a -> a) are natural
transformations either:
zero _ = id
one f = f
two f = f . f
three f = f . f . f
etc.
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131214/e0377471/attachment-0001.html>
------------------------------
Message: 3
Date: Fri, 13 Dec 2013 16:03:23 -0500
From: Andrew Fleckenstein <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Error with floats in implementation of
Horner's method.
Message-ID:
<CAAN9LwtawGc=dt5fdsjaokynvunfm2r85qqyrhb0_7gyjwy...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi all,
I have implemented Horner's method for evaluating a polynomial as follows:
-- the nth horner element, given a list of coefficients and a value at
which it needs to be evaluated
horner_element l x n
| n == (length l)-1 = last l
| otherwise = (l !! n) + (horner_element l x (n+1))*x
-- compute a polynomial given as a list of coefficients at the value x
using horner's method.
horner l x = horner_element l x 0
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131213/5cdd2839/attachment-0001.html>
------------------------------
Message: 4
Date: Fri, 13 Dec 2013 16:07:42 -0500
From: Andrew Fleckenstein <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Error with floats in implementation
of Horner's method.
Message-ID:
<caan9lwshl7svkjbraaoy_cvgwbm5jnox8obc8nrhm+ygpni...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
And I have sent the email before it was finished, oops.
Evaluating at integer values works fine, but trying to do
*Main> let a = [-1,2,-6,2]
*Main> horner a 1.23
gives this error
<interactive>:4:10:
No instance for (Fractional Integer)
arising from the literal `1.23'
Possible fix: add an instance declaration for (Fractional Integer)
In the second argument of `horner', namely `1.23'
In the expression: horner a 1.23
In an equation for `it': it = horner a 1.23
I know it has something to do with types, but whenever I try to add a type
signature to the functions it just messes everything up even more. Any help
would be appreciated
Thanks,
Andrew
On Fri, Dec 13, 2013 at 4:03 PM, Andrew Fleckenstein <
[email protected]> wrote:
> Hi all,
>
> I have implemented Horner's method for evaluating a polynomial as follows:
>
> -- the nth horner element, given a list of coefficients and a value at
> which it needs to be evaluated
>
> horner_element l x n
> | n == (length l)-1 = last l
> | otherwise = (l !! n) + (horner_element l x (n+1))*x
>
> -- compute a polynomial given as a list of coefficients at the value x
> using horner's method.
>
> horner l x = horner_element l x 0
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131213/8ff10dfb/attachment-0001.html>
------------------------------
Message: 5
Date: Sat, 14 Dec 2013 04:20:52 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Error with floats in implementation
of Horner's method.
Message-ID:
<CAPY+ZdQzNzz4c=38+bq7g0nodzxzyegc0sqyh+9otc35za+...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Sat, Dec 14, 2013 at 4:07 AM, Andrew Fleckenstein <
[email protected]> wrote:
> I know it has something to do with types,
Right! :)
> but whenever I try to add a type signature to the functions it just messes
> everything up even more.
This works: let a :: [Double]; a = [-1,2,-6,2]
This works too: let a :: Num a => [a]; a = [-1,2,-6,2]
What do you think are the pros and cons of either?
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131214/aa9c69b5/attachment-0001.html>
------------------------------
Message: 6
Date: Fri, 13 Dec 2013 16:51:25 -0500
From: Andrew Fleckenstein <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Error with floats in implementation
of Horner's method.
Message-ID:
<caan9lws7-bu+ajgav1pmk5atusj5tv6gdsxvb_tjyvckf7g...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I know Num is a class, and Double is an instance of the Num class. I guess
using Num would make it more generic, but I don't see why either one would
be better in this particular function.
On Fri, Dec 13, 2013 at 4:20 PM, Kim-Ee Yeoh <[email protected]> wrote:
>
> On Sat, Dec 14, 2013 at 4:07 AM, Andrew Fleckenstein <
> [email protected]> wrote:
>
>> I know it has something to do with types,
>
>
> Right! :)
>
>
>> but whenever I try to add a type signature to the functions it just
>> messes everything up even more.
>
>
> This works: let a :: [Double]; a = [-1,2,-6,2]
>
> This works too: let a :: Num a => [a]; a = [-1,2,-6,2]
>
> What do you think are the pros and cons of either?
>
> -- Kim-Ee
>
> _______________________________________________
> 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/20131213/87f761cf/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 66, Issue 10
*****************************************