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: pattern matching to data inside a list (Francesco Bochicchio)
2. Getting source libraries (Zachary Turner)
3. Re: beginner's type error (Edward Z. Yang)
4. Re: Getting source libraries (Jason Dusek)
5. Re: Getting source libraries (Zachary Turner)
6. Why doesn't ghci load this? (Jeff Lasslett)
7. Re: Re: Tutorial/Book with Exercises (Zachary Turner)
----------------------------------------------------------------------
Message: 1
Date: Fri, 27 Mar 2009 15:05:14 +0100
From: Francesco Bochicchio <[email protected]>
Subject: Re: [Haskell-beginners] pattern matching to data inside a
list
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
2009/3/27 Michael Mossey <[email protected]>
> Is there a way to pattern match to a list argument and get a list? For
> example, I have this:
>
> -- A LayoutItem has a center position (point), and the four ints are
> -- "left width", "rigth width", "top height", and "bottom height"
> data LayoutItem = LayoutItem Point Int Int Int Int
> deriving Show
>
> -- This computes the left width of a group of composited LayoutItem.
> compositeLeftWidth :: [LayoutItem] -> Int
> compositeLeftWidth items = let
> itemsPosX = [ x | LayoutItem (Point (x,_)) _ _ _ _ <- items ]
> itemsLW = [ lw | LayoutItem _ lw _ _ _ <- items ]
> z = zipWith (\x y -> x-y+1) itemsPosX itemsLW
> in (minimum z) - 1
>
> What I'm wondering is if I could somehow do something like
>
> compositeLeftWidth [ LayoutItem Point( x, _ ) lw _ _ _ ] = ...
>
> and that x and lw would each be the lists I'm calling itemsPosX and itemsLW
> above.
>
> Thanks,
> Mike
>
> That would be neat :-). But IIRC there is no syntax for that.
However, if you are interested in other suggestions (by a very newbie, so
they could be off-mark):
1. if you use a definition like this
data LayoutItem = LayoutItem { x :: Point; leftw, rightw, toph, bottomh
:: Int }
deriving Show
then you could do, using the data accessor functions implicitely defined by
the above code:
xlist = map x items
lwlist = map leftw items
which is basically the same of your list comprehensions, but takes less
characters :-)
2. If I read correctly your code, you are processing a single element of
'items' per time. If so, instead
of building lists of attributes and the zipWith them to get your result,
you could use this approach:
a. define a function tha process a single item of type Layout, like :
compLW LayoutItem x lw rw th bh = x - lw + 1
-- not sure it has the same result, but you get the idea
b. use map (or list comprehension) to build z from items:
compositeLeftWidth items = ( minimum z) -1
where z = map compLW items
This way you avoid to scan multiple times the same list.
Ciao
-------
FB
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090327/04a1c058/attachment-0001.htm
------------------------------
Message: 2
Date: Fri, 27 Mar 2009 09:24:45 -0500
From: Zachary Turner <[email protected]>
Subject: [Haskell-beginners] Getting source libraries
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Suppose I installed a GHC binary package, and now I decide I want source for
all my libraries. What is the easiest way to go about doing this? In
theory I could download every source package individually and unpack the
source into my directory tree, but this is really a last resort since there
are a lot of libraries.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090327/e4042d6f/attachment-0001.htm
------------------------------
Message: 3
Date: Fri, 27 Mar 2009 11:28:54 -0400 (EDT)
From: "Edward Z. Yang" <[email protected]>
Subject: Re: [Haskell-beginners] beginner's type error
To: Brent Yorgey <[email protected]>
Cc: [email protected]
Message-ID: <alpine.deb.2.00.0903271127440.16...@javelin>
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
On Fri, 27 Mar 2009, Brent Yorgey wrote:
>> thing n = n + fromIntegral (round (sqrt n))
thing :: Floating a => a -> a
>> thing n = n + round (sqrt (fromIntegral n))
thing :: Integral a => a -> a
That is, the return types of the method are different?
> Pop quiz for beginners: both of these solve the original problem, but
> they are not quite the same. What is the difference? (Do not answer
> this question if you are not a beginner!)
------------------------------
Message: 4
Date: Fri, 27 Mar 2009 14:43:20 -0700
From: Jason Dusek <[email protected]>
Subject: Re: [Haskell-beginners] Getting source libraries
To: Zachary Turner <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
The GHC source distribution will get you all the sources for all the all the
libraries that come with GHC.
As for any other libraries -- you should have the sources for those already,
if they were installed via Cabal.
--
Jason Dusek
|...source distribution...|
http://www.haskell.org/ghc/download_ghc_6_10_1.html#sources
------------------------------
Message: 5
Date: Fri, 27 Mar 2009 16:53:34 -0500
From: Zachary Turner <[email protected]>
Subject: Re: [Haskell-beginners] Getting source libraries
To: Jason Dusek <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On Fri, Mar 27, 2009 at 4:43 PM, Jason Dusek <[email protected]> wrote:
> The GHC source distribution will get you all the sources for all the all
> the
> libraries that come with GHC.
>
> As for any other libraries -- you should have the sources for those
> already,
> if they were installed via Cabal.
>
Well, I've downloaded it, but how to install them without
building/installing GHC? For example, in the source package all the library
folders have names like "array", "base", etc. In my binary installation
they have names like "array-0.2.0.0" and "base-3.0.3.0". There's a number
of ways I can figure out to deal with, like a perl script etc, but I thought
maybe there is an easier, "official" way to do it. I really don't know
anything about cabal or the GHC build system yet, but was looking for like
an "install source" or "update source" or "make and install libraries"
command either through cabal or the GHC makefile.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090327/9fb241e6/attachment-0001.htm
------------------------------
Message: 6
Date: Sat, 28 Mar 2009 15:59:23 +1100
From: Jeff Lasslett <[email protected]>
Subject: [Haskell-beginners] Why doesn't ghci load this?
To: [email protected]
Message-ID: <1238216363.9590.4.ca...@lass-book>
Content-Type: text/plain
Hi,
I've been making my way through the exercises in the book "Real World
Haskell". Below is my solution to an exercise asking for an
implementation of groupBy in term sof a foldr. I haven't tested it
extensively but is seems to work.
GHCI rejects it though, if I uncomment the type signature for the 'step'
function. Could someone please help me to understand why that is?
Thanks,
Jeff
myGroupBy :: (a -> a -> Bool) -> [a] -> [[a]]
myGroupBy p xs =
foldr step [[]] xs
where
-- step :: a -> [ [ a ] ] -> [ [ a ] ]
step x acc@( ys : yss )
| null ys = [ x ] : []
| p x ( head ys ) = ( x : ys ) : yss
| ( p x ( head ys ) ) == False = [ x ] : acc
------------------------------
Message: 7
Date: Sat, 28 Mar 2009 00:10:00 -0500
From: Zachary Turner <[email protected]>
Subject: Re: [Haskell-beginners] Re: Tutorial/Book with Exercises
To: Jason White <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On Fri, Mar 27, 2009 at 4:00 AM, Jason White <[email protected]> wrote:
> Michael Mossey <[email protected]> wrote:
>
> >YAHT has some hard exercises, early on. He introduces continuations in
> >chapter 4, briefly, and then casually asks you to rewrite map and filter
> > in continuation-passing-style. I was stumped.
>
> So am I.
>
> Do you have any hints for these, without giving the answers away (I know
> the
> answers are in the appendix if I really need them)?
>
Alright well I just solved this one after a considerable amount of effort.
The best hint I can offer without giving too much away is to try to think of
a way to implement map and filter in a tail recursive manner (without CPS).
In other words, the return value of the call to map (or filter), should
itself be the recursive call to map (or filter). Writing map and filter in
this manner, the pattern may begin to be more familiar. If you want a more
detailed hint feel free to email me privately, but I don't want to give
anything away to those who would rather not see any more.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090328/67d76453/attachment.htm
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 9, Issue 36
****************************************