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.  Using Either and Maybe (Alan Buxton)
   2. Re:  Using Either and Maybe (Dan Serban)
   3. Re:  cabal problems (Patrick Wheeler)
   4. Re:  Using Either and Maybe (Benjamin Edwards)
   5. Re:  cabal problems (Kees Bleijenberg)
   6. Re:  Using Either and Maybe (Alan Buxton)


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

Message: 1
Date: Sun, 4 May 2014 16:28:32 +0100
From: "Alan Buxton" <[email protected]>
To: <[email protected]>
Subject: [Haskell-beginners] Using Either and Maybe
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

So I had a function that would leave me with a Nothing or a Just, and I
wanted to use the result of this function to lookup in a Map. So something
like this was very easy to do.

 

h> let list = Data.Map.fromList [(1,2),(3,4),(5,6)]

 

h> Just 4 >>= flip Data.Map.lookup list

Nothing

 

h> Just 3 >>= flip Data.Map.lookup list

Just 4

 

Now, however, my source function gives me an Either. I ended up writing this
function to let me chain Either with Data.Map.lookups:

 

(>>?=) :: (Either a b, a) -> (b -> Maybe c) -> (Either a c,a)

(>>?=) (Left x,e) _ = (Left x,e)

(>>?=) (Right y,e) f = case f y of 

                        Nothing -> (Left e,e)

                        Just z -> (Right z,e)

 

But I can't help thinking I'm reinventing the wheel here somehow. There must
be a better way, right?

 

Thanks in advance for any pointers.


Alan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140504/1446097e/attachment-0001.html>

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

Message: 2
Date: Sun, 4 May 2014 18:42:01 +0300
From: Dan Serban <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Using Either and Maybe
Message-ID:
        <CAHaPvScy7t9Ks-hMK377tH6Vz3S2+8jO-ED=CF5=2Poo-6n0=g...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hi Alan,

Check out these two functions, they point you towards how to write
more idiomatic code. They are called smart destructors, google that
term for more information:

?> :i maybe
maybe :: b -> (a -> b) -> Maybe a -> b  -- Defined in `Data.Maybe'
?> :i either
either :: (a -> c) -> (b -> c) -> Either a b -> c
        -- Defined in `Data.Either'


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

Message: 3
Date: Sun, 4 May 2014 16:35:20 -0500
From: Patrick Wheeler <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] cabal problems
Message-ID:
        <CAAo_BYZ5tuwn66Dhu=f=f87f0b-xy_9j8g2vr5oyzoafqm7...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I have not run into that problem before.

I would download:
http://hackage.haskell.org/packages/index.tar.gz

There is a link for it near the bottom of the main page:
http://hackage.haskell.org

On my mac i would copy it to:

~/.cabal/packages/hackage.haskell.org/.

I am not sure where the cabal directory is on windows though.

If that does not work another option wold but to download the source for
cabal-install and compile it.

cabal unpack cabal-install, or grab the tarball at the bottom of:
http://hackage.haskell.org/package/cabal-install

cd into the directory and use `cabal install`

That should work if you have all of the dependancies already on your
computer. If you don't and the missing dependency list is large(cabal
configure can tell you what you are missing) then it might just be quicker
to reinstall the haskell platform.

Hope that helps,

Patrick


On Sat, May 3, 2014 at 1:09 PM, Kees Bleijenberg <[email protected]
> wrote:

> I don?t know exactly how, but suddenly I get cabal errors.
>
> If I do cabal update there are no errors, everything is fine.
>
> Cabal install caball-install => cabal: internal error when reading
> packages  index: could not read tar file entry. The package index or
> package cache is probably corrupt. Running cabal update might fix it.
>
> Every  install or update shows the same error message.
>
>
>
> I?am using win7 64 bits, Haskell platform 2013.2.0.0. If i do  cabal  - -
> version => cabal install version 1.18.0.2 using version 1.18.1 of the cabal
> library.
>
> On Google the advice is to clear the directory
> c:\users\<user>\appData\roaming\cabal empty.  But that removes all my
> packages. Isn?t there an easier way?
>
> I have never used cabal sandboxes (at least not on purpose)
>
>
>
> Kees
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>


-- 
Patrick Wheeler
[email protected]
[email protected]
[email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140504/8036dd03/attachment-0001.html>

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

Message: 4
Date: Mon, 05 May 2014 09:30:12 +0000
From: Benjamin Edwards <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Using Either and Maybe
Message-ID:
        <can6k4ng4g_a-8+kuszh74ppwezsr6i0kia+6if3c6oecm55...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

You might also consider looking at the errors package on hackage.
specifically hush and note for converting between Either and Maybe. They
are defined 
here<http://hackage.haskell.org/package/errors-1.2.1/docs/Control-Error-Util.html>
.

Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140505/8a246318/attachment-0001.html>

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

Message: 5
Date: Mon, 5 May 2014 11:32:02 +0200
From: "Kees Bleijenberg" <[email protected]>
To: "'The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell'" <[email protected]>
Subject: Re: [Haskell-beginners] cabal problems
Message-ID: <000c01cf6844$df4acd80$9de06880$@[email protected]>
Content-Type: text/plain;       charset="UTF-8"

Thanks Patrick. I think cabal on Windows is different. There is no index.tar.gz 
on my computer. Maybe I'll wait for a new release of the Haskell Platform to 
install GHC again :-(

Additonal: a few days ago I tried to install eclipseFP and the installation 
failed with a cabal error (don't know what error).  Maybe that is the source of 
my problems?.?

Kees
=========================

Van: Beginners [mailto:[email protected]] Namens Patrick Wheeler
Verzonden: zondag 4 mei 2014 23:35
Aan: The Haskell-Beginners Mailing List - Discussion of primarily 
beginner-level topics related to Haskell
Onderwerp: Re: [Haskell-beginners] cabal problems

I have not run into that problem before.

I would download:
http://hackage.haskell.org/packages/index.tar.gz

There is a link for it near the bottom of the main page:
http://hackage.haskell.org

On my mac i would copy it to:

~/.cabal/packages/hackage.haskell.org/.

I am not sure where the cabal directory is on windows though.

If that does not work another option wold but to download the source for 
cabal-install and compile it.

cabal unpack cabal-install, or grab the tarball at the bottom of:
http://hackage.haskell.org/package/cabal-install

cd into the directory and use `cabal install`

That should work if you have all of the dependancies already on your computer. 
If you don't and the missing dependency list is large(cabal configure can tell 
you what you are missing) then it might just be quicker to reinstall the 
haskell platform.

Hope that helps,

Patrick

On Sat, May 3, 2014 at 1:09 PM, Kees Bleijenberg <[email protected]> 
wrote:
I don?t know exactly how, but suddenly I get cabal errors.
If I do cabal update there are no errors, everything is fine.
Cabal install caball-install => cabal: internal error when reading packages  
index: could not read tar file entry. The package index or package cache is 
probably corrupt. Running cabal update might fix it.
Every  install or update shows the same error message.
 
I?am using win7 64 bits, Haskell platform 2013.2.0.0. If i do  cabal  - - 
version => cabal install version 1.18.0.2 using version 1.18.1 of the cabal 
library.
On Google the advice is to clear the directory 
c:\users\<user>\appData\roaming\cabal empty.  But that removes all my packages. 
Isn?t there an easier way?
I have never used cabal sandboxes (at least not on purpose)
 
Kees
 
 

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners




-- 
Patrick Wheeler
[email protected]
[email protected]
[email protected] 
________________________________________
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2014.0.4570 / Virus Database: 3931/7439 - Release Date: 05/04/14



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

Message: 6
Date: Mon, 5 May 2014 11:15:38 +0100
From: "Alan Buxton" <[email protected]>
To: "'The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell'" <[email protected]>
Subject: Re: [Haskell-beginners] Using Either and Maybe
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

Thanks Dan and Ben ? these are exactly what I was looking for.

 

Alan

 

From: Beginners [mailto:[email protected]] On Behalf Of Benjamin 
Edwards
Sent: 05 May 2014 10:30
To: [email protected]
Subject: Re: [Haskell-beginners] Using Either and Maybe

 

You might also consider looking at the errors package on hackage. specifically 
hush and note for converting between Either and Maybe. They are defined here 
<http://hackage.haskell.org/package/errors-1.2.1/docs/Control-Error-Util.html> .

 

Ben

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140505/fe0935b3/attachment.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 71, Issue 7
****************************************

Reply via email to