Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

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 <hyang...@gmail.com>
Subject: Re: [Haskell-beginners] hide Perl code inside Haskell program
To: Jos? Prous <hien...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <f31db34d0909111418q36ec8889y5deae601fc08...@mail.gmail.com>
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 <hien...@gmail.com> 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 <hyang...@gmail.com> 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
>> Beginners@haskell.org
>> 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 <alexey.sklad...@gmail.com>
Subject: Re: [Haskell-beginners] hide Perl code inside Haskell program
To: beginners@haskell.org
Message-ID: <200909121219.42576.alexey.sklad...@gmail.com>
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 <m...@alumni.caltech.edu>
Subject: [Haskell-beginners] Maybe, Either
To: beginners@haskell.org
Message-ID: <4aabbad4.4090...@alumni.caltech.edu>
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 <nonow...@gmail.com>
Subject: Re: [Haskell-beginners] Maybe, Either
To: Michael Mossey <m...@alumni.caltech.edu>
Cc: beginners@haskell.org
Message-ID:
        <d17c24b90909120851h3a5e61eaw124b8832510eb...@mail.gmail.com>
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 <m...@alumni.caltech.edu> 
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
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>


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

Message: 5
Date: Sat, 12 Sep 2009 21:13:58 +0300
From: Michael Snoyman <mich...@snoyman.com>
Subject: Re: [Haskell-beginners] Maybe, Either
To: Yusaku Hashimoto <nonow...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <29bf512f0909121113q6f47b3d3s3bee5328237c4...@mail.gmail.com>
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 <nonow...@gmail.com>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 <m...@alumni.caltech.edu>
> 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
> > Beginners@haskell.org
> > http://www.haskell.org/mailman/listinfo/beginners
> >
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> 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 <byor...@seas.upenn.edu>
Subject: Re: [Haskell-beginners] Maybe, Either
To: beginners@haskell.org
Message-ID: <20090913124011.ga31...@seas.upenn.edu>
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 <john.moor...@gmail.com>
Subject: [Haskell-beginners] parse error on input
To: beginners@haskell.org
Message-ID:
        <4f7ad1ad0909131101x4f582b3cq960ea6ab1800e...@mail.gmail.com>
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 <co...@colina.demon.co.uk>
Subject: Re: [Haskell-beginners] parse error on input
To: John Moore <john.moor...@gmail.com>
Cc: beginners@haskell.org
Message-ID: <m3ws424sxb....@colina.demon.co.uk>
Content-Type: text/plain; charset=us-ascii

>>>>> "John" == John Moore <john.moor...@gmail.com> 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
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 15, Issue 8
****************************************

Reply via email to