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.  Hello World (John M. Dlugosz)
   2. Re:  Hello World (Mateusz Kowalczyk)
   3.  What does the "!n" mean? (John M. Dlugosz)
   4. Re:  Hello World (Brent Yorgey)
   5. Re:  Hello World (Norbert Melzer)
   6. Re:  What does the "!n" mean? (Mateusz Kowalczyk)
   7. Re:  What does the "!n" mean? (Brent Yorgey)


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

Message: 1
Date: Wed, 26 Mar 2014 17:40:14 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Hello World
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

I'm learning Haskell as a background activity, and just wanted to introduce 
myself and get 
the list subscription stuff sorted out.

My primary machine runs Windows 7.  I have Haskell Platform working OK 
including GCHi-Win, 
but could not get Lekseh to work.  However, trying that showed me the world of 
Cabel, and 
I have yet to find an introduction/tutorial on that.  The Haskell Platform 
comes with some 
libraries, but doesn't have a Cabel tool or anything I'd reconize as a 
repository, like 
Lekseh was setting up.

It's said that the best feature of Perl is CPAN.  I suppose Cabel is Haskell's 
equivalent 
of that, or aims to be.  So, what's up with that?  Starting from a blank prompt 
(that can 
run ghc successfully) now what?

?John



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

Message: 2
Date: Thu, 27 Mar 2014 01:03:07 +0000
From: Mateusz Kowalczyk <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Hello World
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

On 26/03/14 22:40, John M. Dlugosz wrote:
> I'm learning Haskell as a background activity, and just wanted to introduce 
> myself and get 
> the list subscription stuff sorted out.
> 
> My primary machine runs Windows 7.  I have Haskell Platform working OK 
> including GCHi-Win, 
> but could not get Lekseh to work.  However, trying that showed me the world 
> of Cabel, and 
> I have yet to find an introduction/tutorial on that.  The Haskell Platform 
> comes with some 
> libraries, but doesn't have a Cabel tool or anything I'd reconize as a 
> repository, like 
> Lekseh was setting up.

Hi.

Firstly, the tools in question are called ?Leksah? and ?Cabal? (note the
?a? as the second from last letter).

Regarding your questions, there is a Cabal user guide at [1]. I don't
know for sure but I imagined that Haskell Platform comes with Cabal.
There are two thinks people think of when they say Cabal: there is Cabal
the library and cabal-install, the binary. You can find very quick
demonstration of cabal-install at [2] although I'm sure that the user
guide covers it. cabal-install is the actual tool that will go out to
the world and fetch packages for you.

Normally to run cabal-install, we simply run the ?cabal? command. I see
that Leksah is on Hackage which means that in theory, one should be able
to just invoke ?cabal install leksah?. I don't know how usable it is
today so if you somehow fail to install it or don't like it, I'd advise
looking at getting a plugin for Haskell for your existing editor. I
don't know about vim but a popular choice for Haskell is haskell-mode.
See the Haskell wiki page on emacs if you're interested[3]. Hopefully
Leksah works just fine for you.

> It's said that the best feature of Perl is CPAN.  I suppose Cabel is 
> Haskell's equivalent 
> of that, or aims to be.  So, what's up with that?  Starting from a blank 
> prompt (that can 
> run ghc successfully) now what?

I can't say whether it's like CPAN but from the vague memory of using
CPAN a along time ago, I think it would be, yes.

> ?John
> 
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
> 

[1]: http://www.haskell.org/cabal/users-guide/
[2]: http://www.haskell.org/haskellwiki/Cabal-Install
[3]: http://www.haskell.org/haskellwiki/Emacs

-- 
Mateusz K.


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

Message: 3
Date: Wed, 26 Mar 2014 20:15:07 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] What does the "!n" mean?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

I'm reading http://www.haskell.org/haskellwiki/IO_inside#inlinePerformIO and it 
shows a 
passage of code:

write :: Int -> (Ptr Word8 -> IO ()) -> Put ()
write !n body = Put $ \c buf@(Buffer fp o u l) ->
   if n <= l
     then write' c fp o u l
     else write' (flushOld c n fp o u) (newBuffer c n) 0 0 0

   where {-# NOINLINE write' #-}
         write' c !fp !o !u !l =
           -- warning: this is a tad hardcore
           inlinePerformIO
             (withForeignPtr fp
               (\p -> body $! (p `plusPtr` (o+u))))
           `seq` c () (Buffer fp o (u+n) (l-n))

I got as far as the second line, looking things up in this index 
<http://hackage.haskell.org/package/base-4.6.0.1/docs/doc-index.html>

But ?write !n body = ??
I understand write is defined to be a function taking an Int and another 
function,
but what does !n mean?  I went through the 2010 Report (BTW, the PDF is useless 
for 
searching for the ! character so I used the HTML version page-by-page) and 
found it used 
as a modifier for named record fields (it says "strict" but I think it's 
describing 
non-optional).
Then I went through the GHC users guide for language extensions, and found a 
reference in 
?7.2.1 without explanation but as an example where the difference between
        f x = let (Foo a b, w) = ..rhs.. in ..body..
and     f x = let !(Foo a b, w) = ..rhs.. in ..body..
is "you must make any such pattern-match strict".
Strict pattern matching is not mentioned elsewhere nor is it in the Haskell 
Report, so 
what am I missing?  I suspect that the usage I'm asking about is related.

The GHC users guide also mentions it again in ?7.4.6 which I think is a 
reference to the 
same feature, ?You can use strictness annotations, in the obvious places in the 
constructor type? but that's for use with a completely different extension 
(GADT types)

I also recognize the ?@? mark as naming the entire variable rather than just 
the parts of 
the pattern matched, but ?buf? is not actually used anywhere, so does it mean 
something 
different, or has other effects, or what?

Thanks in advance,
?John



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

Message: 4
Date: Wed, 26 Mar 2014 21:18:27 -0400
From: Brent Yorgey <[email protected]>
To: "John M. Dlugosz" <[email protected]>
Cc: [email protected]
Subject: Re: [Haskell-beginners] Hello World
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Wed, Mar 26, 2014 at 05:40:14PM -0500, John M. Dlugosz wrote:
> I'm learning Haskell as a background activity, and just wanted to
> introduce myself and get the list subscription stuff sorted out.
> 
> My primary machine runs Windows 7.  I have Haskell Platform working
> OK including GCHi-Win, but could not get Lekseh to work.  However,
> trying that showed me the world of Cabel, and I have yet to find an
> introduction/tutorial on that.  The Haskell Platform comes with some
> libraries, but doesn't have a Cabel tool or anything I'd reconize as
> a repository, like Lekseh was setting up.
> 
> It's said that the best feature of Perl is CPAN.  I suppose Cabel is
> Haskell's equivalent of that, or aims to be.  So, what's up with
> that?  Starting from a blank prompt (that can run ghc successfully)
> now what?

In particular, the counterpart to CPAN is called Hackage, and can be found here:

  http://hackage.haskell.org/

With the Haskell Platform you should have a tool called 'cabal' which
will actually fetch and install packages from Hackage for you (among
other things).

-Brent


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

Message: 5
Date: Thu, 27 Mar 2014 02:23:45 +0100
From: Norbert Melzer <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Hello World
Message-ID:
        <ca+bcvss6zqxfwrapsffvgpdqdhd6my9qmwikvtrqdadkk73...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

The last release of Leksah is about 2 years old, but emacs haskel-mode +
ghc-mod is still actively maintained and developed? Even if emacs' learning
curve is steep I would give it a try. I recently switched completely to it,
everything started with haskell?

Also I can say that sublime text 2 has a working haskell plugin.

If you want to have some kind of project tree, sublime text is what you
want to use, if you prefer to work from the CLI then emacs would be the one?


2014-03-27 2:18 GMT+01:00 Brent Yorgey <[email protected]>:

> On Wed, Mar 26, 2014 at 05:40:14PM -0500, John M. Dlugosz wrote:
> > I'm learning Haskell as a background activity, and just wanted to
> > introduce myself and get the list subscription stuff sorted out.
> >
> > My primary machine runs Windows 7.  I have Haskell Platform working
> > OK including GCHi-Win, but could not get Lekseh to work.  However,
> > trying that showed me the world of Cabel, and I have yet to find an
> > introduction/tutorial on that.  The Haskell Platform comes with some
> > libraries, but doesn't have a Cabel tool or anything I'd reconize as
> > a repository, like Lekseh was setting up.
> >
> > It's said that the best feature of Perl is CPAN.  I suppose Cabel is
> > Haskell's equivalent of that, or aims to be.  So, what's up with
> > that?  Starting from a blank prompt (that can run ghc successfully)
> > now what?
>
> In particular, the counterpart to CPAN is called Hackage, and can be found
> here:
>
>   http://hackage.haskell.org/
>
> With the Haskell Platform you should have a tool called 'cabal' which
> will actually fetch and install packages from Hackage for you (among
> other things).
>
> -Brent
> _______________________________________________
> 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/20140327/564ee115/attachment-0001.html>

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

Message: 6
Date: Thu, 27 Mar 2014 01:25:15 +0000
From: Mateusz Kowalczyk <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] What does the "!n" mean?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

On 27/03/14 01:15, John M. Dlugosz wrote:
> I'm reading http://www.haskell.org/haskellwiki/IO_inside#inlinePerformIO and 
> it shows a 
> passage of code:
> 
> write :: Int -> (Ptr Word8 -> IO ()) -> Put ()
> write !n body = Put $ \c buf@(Buffer fp o u l) ->
>    if n <= l
>      then write' c fp o u l
>      else write' (flushOld c n fp o u) (newBuffer c n) 0 0 0
> 
>    where {-# NOINLINE write' #-}
>          write' c !fp !o !u !l =
>            -- warning: this is a tad hardcore
>            inlinePerformIO
>              (withForeignPtr fp
>                (\p -> body $! (p `plusPtr` (o+u))))
>            `seq` c () (Buffer fp o (u+n) (l-n))
> 
> I got as far as the second line, looking things up in this index 
> <http://hackage.haskell.org/package/base-4.6.0.1/docs/doc-index.html>
> 
> But ?write !n body = ??
> I understand write is defined to be a function taking an Int and another 
> function,
> but what does !n mean?  I went through the 2010 Report (BTW, the PDF is 
> useless for 
> searching for the ! character so I used the HTML version page-by-page) and 
> found it used 
> as a modifier for named record fields (it says "strict" but I think it's 
> describing 
> non-optional).
> Then I went through the GHC users guide for language extensions, and found a 
> reference in 
> ?7.2.1 without explanation but as an example where the difference between
>       f x = let (Foo a b, w) = ..rhs.. in ..body..
> and   f x = let !(Foo a b, w) = ..rhs.. in ..body..
> is "you must make any such pattern-match strict".
> Strict pattern matching is not mentioned elsewhere nor is it in the Haskell 
> Report, so 
> what am I missing?  I suspect that the usage I'm asking about is related.
> 
> The GHC users guide also mentions it again in ?7.4.6 which I think is a 
> reference to the 
> same feature, ?You can use strictness annotations, in the obvious places in 
> the 
> constructor type? but that's for use with a completely different extension 
> (GADT types)

It is in fact a strictness annotation which forces ?n? when matching on
it. It is an optimisation technique and if you're just starting out, I
would not worry about it too much. I would advise against putting those
on if you're not sure about the implications as they can make your
performance worse. GHC can in fact often add those itself.

I don't have any official reading for you but if you simply search for
?Haskell strictness? online, you should get quite a few links to Haskell
wiki, the Wikibook, Stack Overflow and some blogs.

> I also recognize the ?@? mark as naming the entire variable rather than just 
> the parts of 
> the pattern matched, but ?buf? is not actually used anywhere, so does it mean 
> something 
> different, or has other effects, or what?

It just seems that someone gave it a name and then didn't use it. It
does not have any extra meaning.

> 
> Thanks in advance,
> ?John
> 
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
> 


-- 
Mateusz K.


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

Message: 7
Date: Wed, 26 Mar 2014 21:25:53 -0400
From: Brent Yorgey <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] What does the "!n" mean?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8

On Wed, Mar 26, 2014 at 08:15:07PM -0500, John M. Dlugosz wrote:
> I'm reading
> http://www.haskell.org/haskellwiki/IO_inside#inlinePerformIO and it
> shows a passage of code:
> 
> write :: Int -> (Ptr Word8 -> IO ()) -> Put ()
> write !n body = Put $ \c buf@(Buffer fp o u l) ->
>   if n <= l
>     then write' c fp o u l
>     else write' (flushOld c n fp o u) (newBuffer c n) 0 0 0
> 
>   where {-# NOINLINE write' #-}
>         write' c !fp !o !u !l =
>           -- warning: this is a tad hardcore
>           inlinePerformIO
>             (withForeignPtr fp
>               (\p -> body $! (p `plusPtr` (o+u))))
>           `seq` c () (Buffer fp o (u+n) (l-n))
> 
> I got as far as the second line, looking things up in this index
> <http://hackage.haskell.org/package/base-4.6.0.1/docs/doc-index.html>
> 
> But ?write !n body = ??
> I understand write is defined to be a function taking an Int and another 
> function,
> but what does !n mean?  I went through the 2010 Report (BTW, the PDF
> is useless for searching for the ! character so I used the HTML
> version page-by-page) and found it used as a modifier for named
> record fields (it says "strict" but I think it's describing
> non-optional).

No, strict does not mean optional vs. non-optional.  It has to do with
lazy evaluation.  In Haskell, by default, expressions are not
evaluated until their value is actually needed. Making something
strict means (to a first approximation) forcing it to be evaluated
right away, whether its value will be needed or not.  That is what all
the exclamation points mean, both in the code you cited above and the
examples you found; they can be used in a bunch of different contexts
but they always have to do with strictness.

Incidentally, that "IO inside" page is not particularly what I would
recommend for beginners to read!  It's like learning about spark plugs
and oil filters on your first day of driving school.

> I also recognize the ?@? mark as naming the entire variable rather
> than just the parts of the pattern matched, but ?buf? is not actually
> used anywhere, so does it mean something different, or has other
> effects, or what?

Nope, you're right, it's simply not used.  Probably just an oversight
on the part of whoever wrote the code.  the buf@ could be deleted and
it wouldn't change anything.

-Brent


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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 69, Issue 37
*****************************************

Reply via email to