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:  why is the :type different in ghci? (Brandon Allbery)
   2. Re:  combining two monads (Ozgur Akgun)
   3. Re:  why is the :type different in ghci? (Antoine Latter)


----------------------------------------------------------------------

Message: 1
Date: Tue, 23 Aug 2011 07:51:15 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] why is the :type different in ghci?
To: Ovidiu Deac <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
        <CAKFCL4U=3OsVez8OcxLW5BNhX2kXbrSj3YYVLbPgHK=_zdn...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Tue, Aug 23, 2011 at 03:36, Ovidiu Deac <[email protected]> wrote:

> I kind of understand what you mean but I don't understand why would
> anybody want this functionality.
>

Nobody else does these days either, which is why I added


> > Common wisdom these days is to disable the monomorphism restriction when
> > working with ghci; there's a growing belief that it has outlived its
> > usefulness.
>

IIUC it used to make typechecking take too long.

-- 
brandon s allbery                                      [email protected]
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110823/6232c210/attachment-0001.htm>

------------------------------

Message: 2
Date: Tue, 23 Aug 2011 12:53:48 +0100
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] combining two monads
To: Daniel Schoepe <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
        <CALzazPCx=+lkoydpxtnhdbd0j9-l5_vs_gkjj3ov0ttpyum...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi.

Daniel already answered the question; here is an alternative definition for
the loadConfig function he gave. Uses type-classes and liftIO. I find it
easier to use type-classes when dealing with monad transformers, especially
if you have more than a couple of them. You get automatic lifting for every
monad transformer in the stack except IO, for which you need to use liftIO.

Please ask if you have any questions.

loadConfig :: (MonadError MyError m, MonadIO m) => String -> m Config
loadConfig _ = do
  liftIO $ putStrLn "foo"
  throwError ConfigError

HTH,
Ozgur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110823/da5e17d9/attachment-0001.htm>

------------------------------

Message: 3
Date: Tue, 23 Aug 2011 09:49:17 -0500
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] why is the :type different in ghci?
To: Ovidiu Deac <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
        <cakjsnqhabwlvusdeobldav4mtgkb8ovet_jxcakv7ahah_5...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Tue, Aug 23, 2011 at 2:36 AM, Ovidiu Deac <[email protected]> wrote:
> Thanks for the explanation.
>
> I kind of understand what you mean but I don't understand why would
> anybody want this functionality.
>

The concerns is that if you write:

> x = <long complex computation>

and then the compiler generalizes the type to be polymorphic, what you
were expecting to only be computed once is instead computed repeatedly
- we can't save off the value to the top level at runtime if the value
at the top level doesn't have a fixed type!

This is why if you write a polymorphic type signature:

> x :: Num a => a
> x = <long complex computation>

the compiler assumes that know what you're doing.

Antoine

>
> On Tue, Aug 23, 2011 at 7:04 AM, Brandon Allbery <[email protected]> wrote:
>> On Mon, Aug 22, 2011 at 23:26, Ovidiu Deac <[email protected]> wrote:
>>>
>>> Prelude> :type map show
>>> map show :: Show a => [a] -> [String]
>>> Prelude> map show [1,2,3]
>>> ["1","2","3"]
>>> Prelude> let f = map show
>>> Prelude> :type f
>>> f :: [()] -> [String]
>>
>> Ah, another victim of the MMR and extended defaulting....
>> Very briefly, the Haskell spec says that a binding without arguments is
>> monomorphic, i.e. must have a single specific type. ?Your "let f =" is such
>> a binding.
>> Extended defaulting is how ghci gets itself out of that situation: ?it looks
>> for a type in the list of default types which can be used to build a
>> concrete type. ?Under standard defaulting rules it would fail, since the
>> default types are Double and Integer and the result would be an inability to
>> pick one; under extended defaulting, () is added and breaks the deadlock.
>> ?So you get a defaulted monomorphic type ([()] -> [String]).
>> If you disable the monomorphism restriction, you will get the most general
>> type which is the same as you got for ":t map show". ?You can also
>> explicitly type f:
>>> let f :: Show a => [a] -> String; f = map show
>>>
>>> <interactive>:1:8:
>>> ? ?No instance for (Num ())
>>> ? ? ?arising from the literal `3'
>>> ? ?Possible fix: add an instance declaration for (Num ())
>>> ? ?In the expression: 3
>>> ? ?In the first argument of `f', namely `[1, 2, 3]'
>>> ? ?In the expression: f [1, 2, 3]
>>
>> And this lovely bizarro-land error is because the Haskell spec causes
>> numeric literals to be translated to applications of fromInteger (so you
>> don't have to explicitly specify whether it's Int, Integer, Double, Word16,
>> etc.), so ghci tries to resolve
>>> f [fromIntegral 1, fromIntegral 2, fromIntegral 3] :: [()] -> [String]
>> in which fromIntegral must be (Integral a => a -> ()), but can't find a
>> fromIntegral instance that produces a ().
>> Common wisdom these days is to disable the monomorphism restriction when
>> working with ghci; there's a growing belief that it has outlived its
>> usefulness.
>>> :set -XNoMonomorphismRestriction
>> --
>> brandon s allbery ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [email protected]
>> wandering unix systems administrator (available) ? ? (412) 475-9364 vm/sms
>>
>>
>
> _______________________________________________
> 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 38, Issue 42
*****************************************

Reply via email to