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.  getopt (Gaius Hammond)
   2. Re:  getopt (Magnus Therning)
   3. Re:  getopt (Stephen Tetley)
   4.  Parsec (C Gosch)
   5.  mayBe stuck (prad)
   6. Re:  mayBe stuck (aditya siram)
   7. Re:  mayBe stuck (aditya siram)


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

Message: 1
Date: Thu, 5 Aug 2010 20:18:16 +0100
From: Gaius Hammond <ga...@gaius.org.uk>
Subject: [Haskell-beginners] getopt
To: Haskell Beginners List <beginners@haskell.org>
Message-ID: <79262549-3d15-4a05-9bf3-3b888df27...@gaius.org.uk>
Content-Type: text/plain; charset="us-ascii"

Hi all,


I have used GetOpt in Python and Ocaml so I am reasonably familiar  
with it, and I have been studying the technique here:


http://www.haskell.org/haskellwiki/High-level_option_handling_with_GetOpt


Can anyone explain to me what is actually happening here:


     opts <- foldl (>>=) (return startOptions) actions

     let Options { optVerbose = verbose
                 , optInput = input
                 , optOutput = output   } = opts
     input >>= output

I understand the fold is evaluating everything in the actions list  
overlaying them onto the startOptions record, then getting these out  
of IO and into the opts record - but where are "verbose", "input" and  
"output" coming from? Are they just aliases?



Any insight gratefully received :-)



Thanks,




G

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100805/805c4d73/attachment-0001.html

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

Message: 2
Date: Thu, 05 Aug 2010 21:12:12 +0100
From: Magnus Therning <mag...@therning.org>
Subject: Re: [Haskell-beginners] getopt
To: beginners@haskell.org
Message-ID: <4c5b1b1c.2030...@therning.org>
Content-Type: text/plain; charset="utf-8"

On 05/08/10 20:18, Gaius Hammond wrote:
> Hi all,
> 
> 
> I have used GetOpt in Python and Ocaml so I am reasonably familiar with
> it, and I have been studying the technique here:
> 
> 
> http://www.haskell.org/haskellwiki/High-level_option_handling_with_GetOpt
> 
> 
> Can anyone explain to me what is actually happening here:
> 
> 
>     opts <- foldl (>>=) (return startOptions) actions
> 
>     let Options { optVerbose = verbose
>                 , optInput = input
>                 , optOutput = output   } = opts
>     input >>= output
> 
> I understand the fold is evaluating everything in the actions list
> overlaying them onto the startOptions record, then getting these out of
> IO and into the opts record - but where are "verbose", "input" and
> "output" coming from? Are they just aliases?

It's an example of pattern matching, it "picks apart" 'opts'.  So, yes,
they are aliases for the values of the "members" of 'opts'.

/M

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
Url : 
http://www.haskell.org/pipermail/beginners/attachments/20100805/3ac51537/signature-0001.bin

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

Message: 3
Date: Thu, 5 Aug 2010 21:14:44 +0100
From: Stephen Tetley <stephen.tet...@gmail.com>
Subject: Re: [Haskell-beginners] getopt
Cc: Haskell Beginners List <beginners@haskell.org>
Message-ID:
        <aanlktikrzczeg4vvfpmckxsx9pk3v5imy_apmbzz0...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

input, output and verbose are bindings introduced by pattern matching
within the let clause.

The Options datatype has field labels optVerbose, optInput and optOutput:

data Options = Options  { optVerbose    :: Bool
                        , optInput      :: IO String
                        , optOutput     :: String -> IO ()
                        }

Pattern matching can elide field labels, this let binding is equivalent:

 let (Options verbose input output) = opts


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

Message: 4
Date: Thu, 5 Aug 2010 23:42:32 +0200
From: C Gosch <ch.go...@googlemail.com>
Subject: [Haskell-beginners] Parsec
To: beginners@haskell.org
Message-ID:
        <aanlktincj8lign7y6ew3wws-ugj282e=whxkjtsxq...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi,
does anyone here know their way around in Parsec?
I'm trying to parse a file which contains some binary parts too.
I have been using Parsec 3.0.1 to parse the first ASCII part, but all the
parsers are
returning Char type tokens, so it would not work with the binary parts ..
is there any way to do this?
I am using Text.Parsec.ByteString.Lazy.

Note that I'm new to Haskell and Parsec, and doing this within a small
project that
I basically do to get a grip on Haskell (and Parsec, because it appears to
be really nifty and I want to learn more about it).

Thanks for any hints,
Christian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100805/934f9662/attachment-0001.html

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

Message: 5
Date: Thu, 5 Aug 2010 15:22:35 -0700
From: prad <p...@towardsfreedom.com>
Subject: [Haskell-beginners] mayBe stuck
To: haskellbeginners <beginners@haskell.org>
Message-ID: <20100805152235.38d09...@gom>
Content-Type: text/plain; charset=US-ASCII

i'm trying to create my own split function with % as delimiter.
so i have
eqD = (=='%')

and send 

    let s = "zaoeu%aeuasnt%staashaeu%nthdanoe%nthd"
    putStrLn $ show $ brS (findIndex eqD s) s 

to a function brS:

brS i ss
    | isNothing i   = ss
    | otherwise     = (take i ss) : (brS newIndex newStr)
                        where
                            newIndex    = findIndex eqD newStr
                            newStr      = drop (i+1) ss

but get the following error:

    Couldn't match expected type `Maybe a' against inferred type `Int'
    In the first argument of `isNothing', namely `i'
    In the expression: isNothing i :: mayBe a
    In a stmt of a pattern guard for
                 the definition of `brS':
          isNothing i :: mayBe a


my understanding is that i need the isNothing because findIndex will
return Just Int or Nothing.

however, i'm not sure how to resolve what seems to me to be an issue
between a Maybe and an Int.



-- 
In friendship,
prad

                                      ... with you on your journey
Towards Freedom
http://www.towardsfreedom.com (website)
Information, Inspiration, Imagination - truly a site for soaring I's


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

Message: 6
Date: Thu, 5 Aug 2010 17:31:48 -0500
From: aditya siram <aditya.si...@gmail.com>
Subject: Re: [Haskell-beginners] mayBe stuck
To: prad <p...@towardsfreedom.com>
Cc: haskellbeginners <beginners@haskell.org>
Message-ID:
        <aanlktimvazvbxdagqb8iolxpzkvkem6iwgarfnc=q...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

This is happening because findIndex has the signature:
findIndex<http://hackage.haskell.org/packages/archive/haskell98/latest/doc/html/List.html#v:findIndex>::
(a -> Bool) -> [a] -> Maybe Int

>From this we know that 'findIndex' can return a 'Just Int' or 'Nothing'.

GHC is telling you that you need to handle the case where the list element
you ask for does not exist and findIndex returns 'Nothing'.

The functions in the Maybe module [1]may be of some help here.

-deech

[1]
http://hackage.haskell.org/packages/archive/haskell98/latest/doc/html/Maybe.html

On Thu, Aug 5, 2010 at 5:22 PM, prad <p...@towardsfreedom.com> wrote:

> i'm trying to create my own split function with % as delimiter.
> so i have
> eqD = (=='%')
>
> and send
>
>    let s = "zaoeu%aeuasnt%staashaeu%nthdanoe%nthd"
>    putStrLn $ show $ brS (findIndex eqD s) s
>
> to a function brS:
>
> brS i ss
>    | isNothing i   = ss
>    | otherwise     = (take i ss) : (brS newIndex newStr)
>                        where
>                            newIndex    = findIndex eqD newStr
>                            newStr      = drop (i+1) ss
>
> but get the following error:
>
>    Couldn't match expected type `Maybe a' against inferred type `Int'
>    In the first argument of `isNothing', namely `i'
>    In the expression: isNothing i :: mayBe a
>    In a stmt of a pattern guard for
>                 the definition of `brS':
>          isNothing i :: mayBe a
>
>
> my understanding is that i need the isNothing because findIndex will
> return Just Int or Nothing.
>
> however, i'm not sure how to resolve what seems to me to be an issue
> between a Maybe and an Int.
>
>
>
> --
> In friendship,
> prad
>
>                                      ... with you on your journey
> Towards Freedom
> http://www.towardsfreedom.com (website)
> Information, Inspiration, Imagination - truly a site for soaring I's
> _______________________________________________
> 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/20100805/2e23cf19/attachment-0001.html

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

Message: 7
Date: Thu, 5 Aug 2010 17:32:59 -0500
From: aditya siram <aditya.si...@gmail.com>
Subject: Re: [Haskell-beginners] mayBe stuck
To: prad <p...@towardsfreedom.com>
Cc: haskellbeginners <beginners@haskell.org>
Message-ID:
        <aanlkti=p8laywgtqa4adahpqja=ugvuo+fklzyp8s...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Sorry didn't read that properly. Hold on.
-deech

On Thu, Aug 5, 2010 at 5:31 PM, aditya siram <aditya.si...@gmail.com> wrote:

> This is happening because findIndex has the signature:
> findIndex<http://hackage.haskell.org/packages/archive/haskell98/latest/doc/html/List.html#v:findIndex>::
>  (a -> Bool) -> [a] -> Maybe Int
>
> From this we know that 'findIndex' can return a 'Just Int' or 'Nothing'.
>
> GHC is telling you that you need to handle the case where the list element
> you ask for does not exist and findIndex returns 'Nothing'.
>
> The functions in the Maybe module [1]may be of some help here.
>
> -deech
>
> [1]
> http://hackage.haskell.org/packages/archive/haskell98/latest/doc/html/Maybe.html
>
>
> On Thu, Aug 5, 2010 at 5:22 PM, prad <p...@towardsfreedom.com> wrote:
>
>> i'm trying to create my own split function with % as delimiter.
>> so i have
>> eqD = (=='%')
>>
>> and send
>>
>>    let s = "zaoeu%aeuasnt%staashaeu%nthdanoe%nthd"
>>    putStrLn $ show $ brS (findIndex eqD s) s
>>
>> to a function brS:
>>
>> brS i ss
>>    | isNothing i   = ss
>>    | otherwise     = (take i ss) : (brS newIndex newStr)
>>                        where
>>                            newIndex    = findIndex eqD newStr
>>                            newStr      = drop (i+1) ss
>>
>> but get the following error:
>>
>>    Couldn't match expected type `Maybe a' against inferred type `Int'
>>    In the first argument of `isNothing', namely `i'
>>    In the expression: isNothing i :: mayBe a
>>    In a stmt of a pattern guard for
>>                 the definition of `brS':
>>          isNothing i :: mayBe a
>>
>>
>> my understanding is that i need the isNothing because findIndex will
>> return Just Int or Nothing.
>>
>> however, i'm not sure how to resolve what seems to me to be an issue
>> between a Maybe and an Int.
>>
>>
>>
>> --
>> In friendship,
>> prad
>>
>>                                      ... with you on your journey
>> Towards Freedom
>> http://www.towardsfreedom.com (website)
>> Information, Inspiration, Imagination - truly a site for soaring I's
>> _______________________________________________
>> 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/20100805/810c79aa/attachment.html

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

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 26, Issue 11
*****************************************

Reply via email to