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. Down in Data.Ord vs GHC.Exts (Matthew O'Connor)
2. Re: Monad instances and type synonyms (Christopher Howard)
3. Re: Down in Data.Ord vs GHC.Exts (Andres L?h)
----------------------------------------------------------------------
Message: 1
Date: Mon, 15 Apr 2013 22:55:19 -0600
From: "Matthew O'Connor" <[email protected]>
Subject: [Haskell-beginners] Down in Data.Ord vs GHC.Exts
To: [email protected]
Message-ID:
<ca+xmmrvjxasjehte_u_lcbz4ar7up7ljdrowgyzjjbnd_0h...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
While attempting to do some sorting, I ran across Down. The docs:
http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Ord.html#t:Downsay
it's in Data.Ord, but GHCi 7.4.1 complains the Down data constructor
isn't in scope, but if I import GHC.Exts (
http://hackage.haskell.org/packages/archive/base/latest/doc/html/GHC-Exts.html#t:Down),
I get the constructor I expect.
Are the docs wrong? Or is there something I'm not doing right to get Down
exported from Data.Ord? Or other things to check?
Thanks,
Matthew
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130415/4d0e3b6a/attachment-0001.htm>
------------------------------
Message: 2
Date: Mon, 15 Apr 2013 21:51:11 -0800
From: Christopher Howard <[email protected]>
Subject: Re: [Haskell-beginners] Monad instances and type synonyms
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On 04/14/2013 04:09 AM, Brent Yorgey wrote:
> On Sat, Apr 13, 2013 at 05:03:57PM -0800, Christopher Howard wrote:
>
> Sorry, what you're trying to do is simply not possible. Type synonyms
> must always be fully applied. So if you want to make Adjustment an
> instance of Monad then you have to make it a newtype.
>
> However... Adjustment already *is* an instance of Monad! (In
> particular ((->) e) is an instance for any type e.) So there's no
> need for you to redeclare an instance yourself. These days I think
> you just have to import Control.Monad to bring the instance in scope.
>
> -Brent
>
Thank you everyone for your patience. I believe what you say about it
already being an instance of Monad, but I don't seem to have convinced
the compiler:
code:
--------
import Control.Monad
-- ...snip...
type Adjustment = (->) SaleVariables
addTax :: Cash -> Adjustment Cash
addTax cash = \v -> cash * (1 + salesTax v)
-- obviously silly to add taxes twice, but work with me here
testrun = addTax 10.00 >>= \c -> addTax c
--------
gives me
code:
--------
No instance for (Monad ((->) SaleVariables))
arising from a use of `>>='
Possible fix:
add an instance declaration for (Monad ((->) SaleVariables))
In the expression: addTax 10.00 >>= \ c -> addTax c
In an equation for `testrun':
testrun = addTax 10.00 >>= \ c -> addTax c
--------
--
frigidcode.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 555 bytes
Desc: OpenPGP digital signature
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130415/a924beb3/attachment-0001.pgp>
------------------------------
Message: 3
Date: Tue, 16 Apr 2013 09:45:12 +0200
From: Andres L?h <[email protected]>
Subject: Re: [Haskell-beginners] Down in Data.Ord vs GHC.Exts
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CALjd_v4c88o24E_GiP3=u9AAQbfgLZrcwHjbJCJF7m=00tj...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Hi Matthrw.
> While attempting to do some sorting, I ran across Down. The docs:
> http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Ord.html#t:Down
> say it's in Data.Ord, but GHCi 7.4.1 complains the Down data constructor
> isn't in scope, but if I import GHC.Exts
> (http://hackage.haskell.org/packages/archive/base/latest/doc/html/GHC-Exts.html#t:Down),
> I get the constructor I expect.
>
> Are the docs wrong? Or is there something I'm not doing right to get Down
> exported from Data.Ord? Or other things to check?
The docs are not wrong, but you are looking at the "latest" docs, and
are using ghc-7.4.1. If you check
http://hackage.haskell.org/packages/archive/base/4.5.0.0/doc/html/Data-Ord.html
(where base-4.5.0.0 is the version of base shipping with ghc-7.4.1),
then you'll see that is exports an instance of Ord for Data.Exts.Down,
but does not include Down. Since ghc-7.6 (or base-4.6.0.0), the module
Data.Ord defines Down.
Rather than figuring out the base version you're using via "ghc-pkg",
you can also look at the Haskell Platform documentation for the
version of the platform you're using. In this case, probably,
http://lambda.haskell.org/platform/doc/2012.2.0.0/
and then look for Data.Ord in the module hierarchy in there.
Cheers,
Andres
--
Andres L?h, Haskell Consultant
Well-Typed LLP, http://www.well-typed.com
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 58, Issue 29
*****************************************