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: Package Documentation (Haddock) (Daniel Fischer)
2. Re: [Haskell-cafe] About "Fun with type functions" example
(Bastian Erdn??)
3. Re: Re: [Haskell-cafe] About "Fun with type functions"
example (Jonas Almstr?m Dureg?rd)
4. Ignoring the result of a monadic computation (Tim Baumgartner)
5. Re: Ignoring the result of a monadic computation
(Aleksandar Dimitrov)
6. Re: Ignoring the result of a monadic computation (Brent Yorgey)
----------------------------------------------------------------------
Message: 1
Date: Thu, 18 Nov 2010 22:18:47 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Package Documentation (Haddock)
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On Thursday 18 November 2010 21:20:45, Bastian Erdnüß wrote:
> On Nov 18, 2010, at 20:46, Daniel Fischer wrote:
> > On Thursday 18 November 2010 20:25:26, Bastian Erdnüß wrote:
> >> Hi,
> >>
> >> I found the Haddock documentation to the packages that came with the
> >> Haskell Platform locally on my machine.
> >>
> >> 1) It's a little bit uncomfortable to always pick the right one by
> >> hand. Is there a more comfortable way like doing e.g. 'haddock
> >> Data.List' (that's not working) to direct to the documentation of a
> >> certain module?
> >
> > Sorry, I don't understand what you want.
>
> No matter. Maybe me not either.
>
> > To view the haddocks, there's an index.html in the docdir, bookmark
> > that in your browser and click from there.
>
> That works for the Modules that came with GHC but not for the others in
> the Haskell Platform. (On the Mac with the Haskell Platform there came
> the GHC.framework and the HaskellPlatform.framework. In the doc folder
> of the GHC.framework is a central index.html in the doc folder of the
> HaskellPlatform, it isn't.) However, still an improvement.
>
Hrrmphh. I thought the platform would come with docs. It probably does,
they're just hiding. You can try
$ locate Graphics-Rendering-OpenGL.html
(random module from one of the HP libs, maybe locate has a different name
on the Mac; find -name should work, but locate tends to be faster).
If that reveals something, the doc root should be a few directories up.
If not, the platform may have come without docs, complain :)
> > If you want to generate haddocks for your project(s) and have it link
> > to the modules you used, the simplest way is to create a .cabal file
> > and let cabal take care of directing haddock to the installed docs
> > (you can do it manually with --read-interface flags, but letting cabal
> > figure out the correct flags is easier).
>
> I'm not that far yet with Haskell. But I mark that note for later.
>
> >> 2) I cannot find the documentation to the packages I post installed
> >> with cabal. I tried to build them using e.g. 'cabal haddock Yampa'
> >> but that's not working. How do I do it right?
> >
> > Edit your ~/.cabal/config, set
> >
> > documentation: True
>
> I just did.
>
A propos,
library-profiling: True
is probably also a good idea, if you want to do any profiling (and sooner
or later you will), you need the libraries you use built for profiling too.
> > there, then cabal builds docs for all packages it installs
> > automatically (and creates a comprehensive index in
> > ~/.cabal/share/doc). Unfortunately, it doesn't build docs for packages
> > it previously installed, so you'd have to reinstall them or create the
> > haddocks manually [the latter may need unpacking the packages]. If you
> > haven't installed many packages yet, reinstalling is probably the
> > simpler route.
>
> Well, there are to much to reinstall everyone per hand, but not to much
> if there is a magic command like 'cabal upgrade --reinstall --all' to do
> it all at once. Any help how to do that?
>
A shell script?
$ cat reinstallEverything.sh
PACKS=`ghc-pkg list --user | grep -v /home`
# remove the location of user-db
cabal install --reinstall --dry-run $PACKS;
If the dry-run output doesn't look too frightening, remove the --dry-run
flag and let it reinstall what you have. (Assumes that the platform
packages are registered in the global package db, otherwise it would try to
reinstall the entire platform too, which would probably not be ideal.)
> >> Thanks for your help in advance,
> >> Bastian
>
> ^^ still valid
------------------------------
Message: 2
Date: Fri, 19 Nov 2010 04:42:09 +0100
From: Bastian Erdn?? <[email protected]>
Subject: [Haskell-beginners] Re: [Haskell-cafe] About "Fun with type
functions" example
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Nov 19, 2010, at 1:07, Daniel Peebles wrote:
> The best you can do with fromInt is something like Int -> (forall n. (Nat n)
> => n -> r) -> r, since the type isn't known at compile time.
Or you put it in the type class as fromInt :: Int -> n and do in Zero: fromInt
_ = Zero and in the other: fromInt _ = Succ $ fromInt (undefined :: n).
Shouldn't that work, too?
> On Thu, Nov 18, 2010 at 2:52 PM, Arnaud Bailly <[email protected]>wrote:
>
>> Thanks a lot, that works perfectly fine!
>> Did not know this one...
>> BTW, I would be interested in the fromInt too.
>>
>> Arnaud
>>
>> On Thu, Nov 18, 2010 at 8:22 PM, Erik Hesselink <[email protected]>
>> wrote:
>>> On Thu, Nov 18, 2010 at 20:17, Arnaud Bailly <[email protected]>
>> wrote:
>>>> Hello,
>>>> I am trying to understand and use the Nat n type defined in the
>>>> aforementioned article. Unfortunately, the given code does not compile
>>>> properly:
>>>
>>> [snip]
>>>
>>>> instance (Nat n) => Nat (Succ n) where
>>>> toInt _ = 1 + toInt (undefined :: n)
>>>
>>> [snip]
>>>
>>>> And here is the error:
>>>>
>>>> Naturals.hs:16:18:
>>>> Ambiguous type variable `n' in the constraint:
>>>> `Nat n' arising from a use of `toInt' at Naturals.hs:16:18-39
>>>> Probable fix: add a type signature that fixes these type variable(s)
>>>
>>> You need to turn on the ScopedTypeVariables extension (using {-#
>>> LANGUAGE ScopedTypeVariables #-} at the top of your file, or
>>> -XScopedTypeVariables at the command line). Otherwise, the 'n' in the
>>> class declaration and in the function definition are different, and
>>> you want them to be the same 'n'.
>>>
>>> Erik
>>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
> _______________________________________________
> Haskell-Cafe mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
------------------------------
Message: 3
Date: Fri, 19 Nov 2010 07:42:15 +0100
From: Jonas Almstr?m Dureg?rd <[email protected]>
Subject: Re: [Haskell-beginners] Re: [Haskell-cafe] About "Fun with
type functions" example
To: Bastian Erdn?? <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Then you can write fromInt 1 :: Zero, and it will type check.
/J
On 19 November 2010 04:42, Bastian Erdnüß <[email protected]> wrote:
>
> On Nov 19, 2010, at 1:07, Daniel Peebles wrote:
>
> > The best you can do with fromInt is something like Int -> (forall n. (Nat
> n)
> > => n -> r) -> r, since the type isn't known at compile time.
>
> Or you put it in the type class as fromInt :: Int -> n and do in Zero:
> fromInt _ = Zero and in the other: fromInt _ = Succ $ fromInt (undefined ::
> n). Shouldn't that work, too?
>
> > On Thu, Nov 18, 2010 at 2:52 PM, Arnaud Bailly <[email protected]
> >wrote:
> >
> >> Thanks a lot, that works perfectly fine!
> >> Did not know this one...
> >> BTW, I would be interested in the fromInt too.
> >>
> >> Arnaud
> >>
> >> On Thu, Nov 18, 2010 at 8:22 PM, Erik Hesselink <[email protected]>
> >> wrote:
> >>> On Thu, Nov 18, 2010 at 20:17, Arnaud Bailly <[email protected]>
> >> wrote:
> >>>> Hello,
> >>>> I am trying to understand and use the Nat n type defined in the
> >>>> aforementioned article. Unfortunately, the given code does not compile
> >>>> properly:
> >>>
> >>> [snip]
> >>>
> >>>> instance (Nat n) => Nat (Succ n) where
> >>>> toInt _ = 1 + toInt (undefined :: n)
> >>>
> >>> [snip]
> >>>
> >>>> And here is the error:
> >>>>
> >>>> Naturals.hs:16:18:
> >>>> Ambiguous type variable `n' in the constraint:
> >>>> `Nat n' arising from a use of `toInt' at Naturals.hs:16:18-39
> >>>> Probable fix: add a type signature that fixes these type variable(s)
> >>>
> >>> You need to turn on the ScopedTypeVariables extension (using {-#
> >>> LANGUAGE ScopedTypeVariables #-} at the top of your file, or
> >>> -XScopedTypeVariables at the command line). Otherwise, the 'n' in the
> >>> class declaration and in the function definition are different, and
> >>> you want them to be the same 'n'.
> >>>
> >>> Erik
> >>>
> >> _______________________________________________
> >> Haskell-Cafe mailing list
> >> [email protected]
> >> http://www.haskell.org/mailman/listinfo/haskell-cafe
> >>
> > _______________________________________________
> > Haskell-Cafe mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>
> _______________________________________________
> 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/20101119/f99fad98/attachment-0001.html
------------------------------
Message: 4
Date: Fri, 19 Nov 2010 07:56:02 +0100
From: "Tim Baumgartner" <[email protected]>
Subject: [Haskell-beginners] Ignoring the result of a monadic
computation
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Hi,
while learning about monads, I had something like
do
line <- getLine
something
putStrLn line
and I wondered if I could write it in one line, without naming of parameters.
I finally came up with
getLine >>= ignore something >>= putStrLn
using
ignore :: Monad m => m a -> b -> m b
ignore m a = m >> return a
I'm satisfied with this solution but searching hoogle I didn't find a standard
function for my ignore. Am I missing something?
Cheers,
Tim
--
GRATIS! Movie-FLAT mit über 300 Videos.
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome
------------------------------
Message: 5
Date: Fri, 19 Nov 2010 14:02:22 +0100
From: Aleksandar Dimitrov <[email protected]>
Subject: Re: [Haskell-beginners] Ignoring the result of a monadic
computation
To: Tim Baumgartner <[email protected]>
Cc: [email protected]
Message-ID: <20101119130221.ga2...@minsk>
Content-Type: text/plain; charset="utf-8"
Hello Tim,
> while learning about monads, I had something like
>
> do
> line <- getLine
> something
> putStrLn line
This is written in do-notation. Let's look at it without do-notation:
> getLine >>= (\line -> something >>= (\_ -> putStrLn line))
Or, using `const` which is probably a bit clearer:
> getLine >>= (\line -> something >>= const $ putStrLn line)
The do-nation implicitly discards the result of 'something,' even though
something may have a result!
In fact, a couple of versions ago, ghc started warning you if 'something' had a
type other than M () and you weren't binding it:
> % cat Test.hs
> main :: IO ()
> main = do print "Hello"
> getChar
> print "Goodbye"
> % ghc -Wall --make Test.hs
> [1 of 1] Compiling Main ( Test.hs, Test.o )
>
> Test.hs:3:10:
> Warning: A do-notation statement discarded a result of type Char.
> Suppress this warning by saying "_ <- getChar",
> or by using the flag -fno-warn-unused-do-bind
So you'd have to rewrite your code like this to compile without warnings:
> do line <- getLine
> _ <- something
> putStrLn line
That way, it is clear that even though you're using the do-notation, you're
discarding the result of a computation, and are executing the computation just
for its side-effects!
> and I wondered if I could write it in one line, without naming of parameters.
As you can see above, one can write it in one line. It is also possible to use
(>>); (>>) is similar to (>>=) except it doesn't *bind* the result. It also has
a different type:
> (>>=) :: m a -> (a -> m b) -> m b
> (>>) :: m a -> m b -> m b
(>>=) expects a function from a to m b as a second argument, but since (>>)
doesn't bind a result at all, such a function wouldn't make any sense! So (>>)
just takes another computation, and chains these. You could rewrite the one-line
statement above as
> getLine >>= (\line -> something >> putStrLn line)
which does read a little better. But the do-notation really does make our lives
easier! It makes the λ-binding of variables more implicit. So we can use it in
the following way:
> do line <- getLine
> something >> putStrLn line
This way, it is clear that something's result is going to be thrown away (if
there is any,) and something is just executed for its side-effects.
> % cat Test.hs
> ~
> something = getChar
>
> main :: IO ()
> main = do line <- getLine
> something >> putStrLn line
> % ghc -Wall --make Test.hs
> % ./Test
> ~
> foobar
> .
> foobar
As you can see, I typed in 'foobar' which got bound to 'line.' But then I got
prompted to also put in a character, which got discarded.
I hope this makes it a little clearer!
A.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: Digital signature
Url :
http://www.haskell.org/pipermail/beginners/attachments/20101119/b5d05217/attachment-0001.bin
------------------------------
Message: 6
Date: Fri, 19 Nov 2010 10:21:10 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Ignoring the result of a monadic
computation
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Fri, Nov 19, 2010 at 07:56:02AM +0100, Tim Baumgartner wrote:
> Hi,
>
> while learning about monads, I had something like
>
> do
> line <- getLine
> something
> putStrLn line
>
> and I wondered if I could write it in one line, without naming of parameters.
> I finally came up with
>
> getLine >>= ignore something >>= putStrLn
>
> using
> ignore :: Monad m => m a -> b -> m b
> ignore m a = m >> return a
>
> I'm satisfied with this solution but searching hoogle I didn't find
> a standard function for my ignore. Am I missing something?
Nope, there isn't such a function, but I like it. It reminds me of
(*>) and (<*) from Control.Applicative. Note that you sometimes see
the name 'ignore' used for a slightly different function, namely
ignore :: Monad m => m a -> m ()
ignore m = m >> return ()
but yours is a bit more general. Other names for your function might
be 'passThrough' or something like that.
-Brent
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 29, Issue 27
*****************************************