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: Question regarding the ListT Monad Transformer
(Tim Cowlishaw)
2. Re: How to avoid Gmail attachments? ("An HTML attachment
was scrubbed") (Peter Schmitz)
3. package random requires two versions of time (Ashish Agarwal)
4. Re: Boilerplate Code (Matt Andrew)
5. Re: package random requires two versions of time
(David Virebayre)
6. Re: Boilerplate Code (Claus Reinke)
7. Re: package random requires two versions of time (Ashish Agarwal)
----------------------------------------------------------------------
Message: 1
Date: Wed, 04 Aug 2010 19:47:41 +0100
From: Tim Cowlishaw <[email protected]>
Subject: Re: [Haskell-beginners] Question regarding the ListT Monad
Transformer
To: "Edward Z. Yang" <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
On 04/08/10 18:42, Edward Z. Yang wrote:
> ListT IO a = IO [a], so you're looking for a function [IO a] -> IO [a].
> This function is called sequence :: Monad m => [m a] -> m [a]
>
>
Aha, yep, that's exactly what I was after! Thanks very much...
> My best advice for you is to get rid of the newtype wrapping and unwrapping
> when you're trying to an understand a monad transformer.
>
Aah I see - that makes sense, Will try and have another crack at them
shortly.
Cheers,
Tim
------------------------------
Message: 2
Date: Wed, 4 Aug 2010 13:33:55 -0700
From: Peter Schmitz <[email protected]>
Subject: Re: [Haskell-beginners] How to avoid Gmail attachments? ("An
HTML attachment was scrubbed")
To: Haskell Beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On Wed, Aug 4, 2010 at 7:17 AM, Amy de Buitléir <[email protected]> wrote:
>
> > "-------------- next part --------------
> > An HTML attachment was scrubbed...
> > URL: ..."
> >
> > The url seems to be a copy of my mail.
>
> In gmail, on the toolbar right above the message, there's a button for
> "plain text". I think that will do the trick.
...
Amy,
Thanks very much!
-- Peter
------------------------------
Message: 3
Date: Wed, 4 Aug 2010 21:29:16 -0400
From: Ashish Agarwal <[email protected]>
Subject: [Haskell-beginners] package random requires two versions of
time
To: Haskell-beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Running 'cabal configure' on one of our code bases gives:
package random-1.0.0.2 requires time-1.1.4
package random-1.0.0.2 requires time 1.2.03
in addition to several other such warnings. This one is the oddest however
since it is the same version of random that presumably requires two
different versions of time. How can that be? Output of 'cabal info random'
gives:
Dependencies: base >= 3 && <5, time -any
This happens only on a Debian system, in which I installed the Haskell
Platform using apt-get.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100804/c548fe10/attachment-0001.html
------------------------------
Message: 4
Date: Thu, 05 Aug 2010 12:07:08 +1000
From: Matt Andrew <[email protected]>
Subject: Re: [Haskell-beginners] Boilerplate Code
To: beginners <[email protected]>
Message-ID: <878w4lbynn.wl%[email protected]>
Content-Type: text/plain; charset=US-ASCII
I had a play today and managed to figure out how to write the code I needed. If
anyone is curious the resulting code is:
{-# LANGUAGE TemplateHaskell #-}
module Template where
import Language.Haskell.TH
typeChecker :: String -> Q Exp
typeChecker schemeType = do
x <- newName "x"
return $ LamE [VarP x] (CaseE (VarE x) [Match (ConP ty [WildP]) (NormalB
(AppE (ConE bool) (ConE true))) [],Match WildP (NormalB (AppE (ConE bool) (ConE
false))) []])
where ty = mkName schemeType
bool = mkName "Bool"
true = mkName "True"
false = mkName "False"
I then import this module into where I am defining the predicates (templates
have to be defined in a seperate module), where the code becomes:
numberP :: SchemeVal -> SchemeVal
numberP = $(typeChecker "Number")
boolP :: SchemeVal -> SchemeVal
boolP = $(typeChecker "Bool")
symbolP :: SchemeVal -> SchemeVal
symbolP = $(typeChecker "Symbol")
So, as I always knew, not really worth the effort as I've written a 13 line
module to save 3 lines of code, but a good learning experience =) Thanks again
for the point in the right direction.
Cheers,
Matt
------------------------------
Message: 5
Date: Thu, 5 Aug 2010 10:14:02 +0200
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] package random requires two versions
of time
To: Ashish Agarwal <[email protected]>
Cc: Haskell-beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, Aug 5, 2010 at 3:29 AM, Ashish Agarwal <[email protected]> wrote:
> Running 'cabal configure' on one of our code bases gives:
> package random-1.0.0.2 requires time-1.1.4
> package random-1.0.0.2 requires time 1.2.03
...
> This happens only on a Debian system, in which I installed the Haskell
> Platform using apt-get.
Did you also install libraries using cabal ? cabal install in your
home directory by default, as a result you can have both global and
user packages, and there can be conflicts.
David.
------------------------------
Message: 6
Date: Thu, 5 Aug 2010 10:50:10 +0200
From: "Claus Reinke" <[email protected]>
Subject: [Haskell-beginners] Re: Boilerplate Code
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
reply-type=original
> {-# LANGUAGE TemplateHaskell #-}
> import Language.Haskell.TH
> typeChecker :: String -> Q Exp
> numberP :: SchemeVal -> SchemeVal
> numberP = $(typeChecker "Number")
TH is a rather big hammer for this nail, isn't it?-)
Spelling out one of the two simpler suggestions from
this thread (the other was to define your own constructor
tags and a mapping from SchemeVal to those tags):
import Data.Data
-- you'd need to derive Data for SchemeVal
-- see DeriveDataTypeable
constructorP :: (Data a) => String -> a -> Bool
constructorP s = (s==) . showConstr . toConstr
numberP :: SchemeVal -> SchemeVal
numberP = Bool . constructorP "Number"
Part of the difference between Haskell and Scheme is that
reflection/meta-programming are not the first tools for
common problems in Haskell. Not just because the evaluator
is a rather heavyweight dependency, but because reflection
tends to interfere with reasoning about programs (even the
use of Data/Show is problematic in this respect - eg, when
renaming some constructors, we would suddenly need to
rename String values as well; so you might prefer the
define-your-own-tags variant instead, if you care about
maintenance/refactoring).
For the scenic tour of pattern match (meta-)programming,
see also QuasiQuotes, which allow you to construct patterns,
or ViewPatterns, which allow you to call functions during
pattern matching, or PatternGuards, which allow you to
do pattern matching in guards).
Those language options are documented here:
http://haskell.org/ghc/docs/latest/html/users_guide/flag-reference.html#id598783
There are some alternatives for reducing the boilerplate -
not necessarily recommended, but useful to know.
I'll use Either and its Left constructor, for simplicity.
- we can avoid layout, to make the failure cases less
prominent - low tech, but succinct:
leftP x = case x of Left{} -> True; _->False
- pattern match failure in list comprehensions gives
empty lists, so we can write
-- count the 'Left _' in the singleton list [x]
leftP x = not.null $ [ () | Left{} <- [x] ]
That is a bit of a hack, but it points in the right
direction:
- we'd really like to write out only the matching
cases of constructor predicates, as the failure
cases are boilerplate; but we need a handle on
pattern match failure, to add in the default code
for the non-matching cases.
-- handle successful match only,
-- use Maybe to indicate pattern match success/failure
leftP' x = case x of Left{} -> Just True;_->Nothing
-- add in default result for failure case
leftP = maybe False id . leftP'
Sadly, that doesn't save us typing here, but it
shows how to decompose code that relies on pattern
match failure and fall-through semantics (it is surprising
how often people think that cannot be done).
A slight variation uses the fact that pattern-match
failure in do-notation calls the Monad method fail,
which -for the Maybe Monad- returns Nothing:
leftP' x = do Left{} <- Just x; Just True
leftP = maybe False id . leftP'
>From there, it isn't far until we define our own pattern
combinators..
int n x = Just (n==x)
left pat x = do Left l <- Just x; pat l
right pat x = do Right r <- Just x; pat r
a+++b = \x->a x `mplus` b x
left (left (int 0)) +++ left (right (int 0)) $ (Left (Right 0))
-> Just True
left (left (int 0)) +++ left (right (int 0)) $ (Left (Right 1))
-> Just False
But that is just an appetizer for those who like to play
with these things, not a recommended way of writing
programs for beginners;-)
Claus
------------------------------
Message: 7
Date: Thu, 5 Aug 2010 10:04:04 -0400
From: Ashish Agarwal <[email protected]>
Subject: Re: [Haskell-beginners] package random requires two versions
of time
To: David Virebayre <[email protected]>
Cc: Haskell-beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
This is on a virtual machine where I just work as root. So all commands I
ran were for the same account (root).
On Thu, Aug 5, 2010 at 4:14 AM, David Virebayre
<[email protected]<dav.vire%[email protected]>
> wrote:
> On Thu, Aug 5, 2010 at 3:29 AM, Ashish Agarwal <[email protected]>
> wrote:
> > Running 'cabal configure' on one of our code bases gives:
> > package random-1.0.0.2 requires time-1.1.4
> > package random-1.0.0.2 requires time 1.2.03
> ...
> > This happens only on a Debian system, in which I installed the Haskell
> > Platform using apt-get.
>
> Did you also install libraries using cabal ? cabal install in your
> home directory by default, as a result you can have both global and
> user packages, and there can be conflicts.
>
> David.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100805/799f0a0c/attachment-0001.html
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 26, Issue 10
*****************************************