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: hide Perl code inside Haskell program (Hong Yang)
2. Re: hide Perl code inside Haskell program (Khudyakov Alexey)
3. Maybe, Either (Michael Mossey)
4. Re: Maybe, Either (Yusaku Hashimoto)
5. Re: Maybe, Either (Michael Snoyman)
6. Re: Maybe, Either (Brent Yorgey)
7. parse error on input (John Moore)
8. Re: parse error on input (Colin Paul Adams)
----------------------------------------------------------------------
Message: 1
Date: Fri, 11 Sep 2009 16:18:01 -0500
From: Hong Yang <[email protected]>
Subject: Re: [Haskell-beginners] hide Perl code inside Haskell program
To: Jos? Prous <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
This way works fine if the program has no arguments. What if I have to pass
arguments such as "-i input -o output"?
Thanks,
Hong
On Thu, Sep 10, 2009 at 12:45 PM, José Prous <[email protected]> wrote:
> you are putting the perl script as the name of the command
> you can do something like: rawSystem "perl" ["-e","print \"testing
> ...\n\";" ]
> this is equivalent to call in the shell: perl -e "print \"testing ...\";"
> (sorry Hong I din't put reply to all in the fist mail)
> On Thu, Sep 10, 2009 at 1:24 PM, Hong Yang <[email protected]> wrote:
>
>> I was trying to hide Perl code inside Haskell program like the following:
>>
>> > module Main where
>>
>> > import System.Environment (getArgs)
>> > import System.Cmd
>>
>> > main = do
>> > args <- getArgs
>> > rawSystem pl args
>> > where pl = "#!/usr/bin/perl\n" ++
>> > "print \"testing ...\n\";"
>>
>> The program can run, but generates no output at all. Can someone tell me
>> any other tricks which might be missing? (Do we need to use pipe here?)
>>
>> Thanks,
>>
>> Hong
>>
>> _______________________________________________
>> 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/20090911/48f22a56/attachment-0001.html
------------------------------
Message: 2
Date: Sat, 12 Sep 2009 12:19:42 +0400
From: Khudyakov Alexey <[email protected]>
Subject: Re: [Haskell-beginners] hide Perl code inside Haskell program
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="utf-8"
Ð ÑообÑении Ð¾Ñ Ð¡ÑббоÑа 12 ÑенÑÑбÑÑ 2009 01:18:01
авÑÐ¾Ñ Hong Yang напиÑал:
> This way works fine if the program has no arguments. What if I have to pass
> arguments such as "-i input -o output"?
>
You can just run perl and feed you program to perl's stdin. With this you can
add all flags you like
Shell
$ echo 'print "fff\n"; $i=1; print "$i\n";' | perl
fff
1
------------------------------
Message: 3
Date: Sat, 12 Sep 2009 08:14:28 -0700
From: Michael Mossey <[email protected]>
Subject: [Haskell-beginners] Maybe, Either
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
I want to use 'lookup' inside an Either String monad. So I want to write
something like
eitherLookup :: Eq a => String -> a -> [(a,b)] -> Either String b
eitherLookup s x ps = case lookup x ps of
Just y -> Right y
Nothing -> Left s
Is there such a function existing?
Thanks,
Mike
------------------------------
Message: 4
Date: Sun, 13 Sep 2009 00:51:56 +0900
From: Yusaku Hashimoto <[email protected]>
Subject: Re: [Haskell-beginners] Maybe, Either
To: Michael Mossey <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
I think there is no such function in standard library.
But you can also do the same by `maybe (Left err) Right (lookup key
assoc)` without defining eitherLookup.
HTH
-nwn
On Sun, Sep 13, 2009 at 12:14 AM, Michael Mossey <[email protected]>
wrote:
> I want to use 'lookup' inside an Either String monad. So I want to write
> something like
>
> eitherLookup :: Eq a => String -> a -> [(a,b)] -> Either String b
> eitherLookup s x ps = case lookup x ps of
> Â Â Â Â Â Â Â Â Â Â Â Â Just y -> Right y
> Â Â Â Â Â Â Â Â Â Â Â Â Nothing -> Left s
>
> Is there such a function existing?
>
> Thanks,
> Mike
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 5
Date: Sat, 12 Sep 2009 21:13:58 +0300
From: Michael Snoyman <[email protected]>
Subject: Re: [Haskell-beginners] Maybe, Either
To: Yusaku Hashimoto <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
I often times have to write a lookup function that returns its value into
any monad instead of just Maybe. For example:
mLookup :: (Eq k, Monad m) => k -> [(k, v)] -> m v
mLookup k pairs = case lookup k pairs of
Nothing -> fail "mLookup: nothing found"
Just v -> return v
Hope that helps.
On Sat, Sep 12, 2009 at 6:51 PM, Yusaku Hashimoto <[email protected]>wrote:
> I think there is no such function in standard library.
>
> But you can also do the same by `maybe (Left err) Right (lookup key
> assoc)` without defining eitherLookup.
>
> HTH
> -nwn
>
> On Sun, Sep 13, 2009 at 12:14 AM, Michael Mossey <[email protected]>
> wrote:
> > I want to use 'lookup' inside an Either String monad. So I want to write
> > something like
> >
> > eitherLookup :: Eq a => String -> a -> [(a,b)] -> Either String b
> > eitherLookup s x ps = case lookup x ps of
> > Just y -> Right y
> > Nothing -> Left s
> >
> > Is there such a function existing?
> >
> > Thanks,
> > Mike
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> >
> _______________________________________________
> 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/20090912/0080fad9/attachment-0001.html
------------------------------
Message: 6
Date: Sun, 13 Sep 2009 08:40:11 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Maybe, Either
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Sat, Sep 12, 2009 at 09:13:58PM +0300, Michael Snoyman wrote:
> I often times have to write a lookup function that returns its value into
> any monad instead of just Maybe. For example:
>
> mLookup :: (Eq k, Monad m) => k -> [(k, v)] -> m v
> mLookup k pairs = case lookup k pairs of
> Nothing -> fail "mLookup: nothing found"
> Just v -> return v
>
This is actually the type that the lookup function USED to have, but
it was changed since monads actually have nothing to do with failing
(the fail method is just a hack used to handle pattern-match failures
in do-notation). Probably a better implementation of this would be
mLookup :: (Eq k, MonadPlus m) => k -> [(k,v)] -> m v
mLookup k pairs = maybe mzero return (lookup k pairs)
-Brent
------------------------------
Message: 7
Date: Sun, 13 Sep 2009 19:01:36 +0100
From: John Moore <[email protected]>
Subject: [Haskell-beginners] parse error on input
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi,
Can anyone explain what I'm doing wrong. I'm learning Haskell using the
book real world haskell. It tells me to load programs and update cabal using
'$' symbol but everytime I enter it tells me parse error on input '$'. The
programs are taken from the book so there nothing wrong with them.What amI
misssing?
Regards
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090913/01151b80/attachment-0001.html
------------------------------
Message: 8
Date: Sun, 13 Sep 2009 19:10:24 +0100
From: Colin Paul Adams <[email protected]>
Subject: Re: [Haskell-beginners] parse error on input
To: John Moore <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
>>>>> "John" == John Moore <[email protected]> writes:
John> Hi, Can anyone explain what I'm doing wrong. I'm learning
John> Haskell using the book real world haskell. It tells me to
John> load programs and update cabal using '$' symbol but
John> everytime I enter it tells me parse error on input '$'. The
John> programs are taken from the book so there nothing wrong with
John> them.What amI misssing?
It sounds like you are mistaking the unix command line prompt symbol
(that is: $) for something you are supposed to type.
E.g. If it says:
$ cabal install
then it means type:
cabal install
at the command line prompt.
--
Colin Adams
Preston Lancashire
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 15, Issue 8
****************************************