Jacob Thomas | 7 Feb 2013 03:37
Favicon

Either example


Hello 

I'm new to Haskell, and need help with figuring out the Either type...
Any example to show how this works?

Jacob

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Alvaro Gutierrez | 7 Feb 2013 05:04
Picon
Favicon

Re: Either example

Often, Either is used to represent, exclusively, a value or a failure, in a more detailed way than Maybe can. For example, a function like `parse` (http://hackage.haskell.org/packages/archive/parsec/latest/doc/html/Text-Parsec-Prim.html#v:parse), which is part of Parsec, might have a type like:

parse :: [...] s -> Either ParseError a

Meaning, parsing will either fail with a Left ParseError, or succeed with a Right a, where a is whatever type your parser returns.

Hope that helps,

Alvaro





On Wed, Feb 6, 2013 at 9:37 PM, Jacob Thomas <jthomas7 <at> ucsc.edu> wrote:

Hello 

I'm new to Haskell, and need help with figuring out the Either type...
Any example to show how this works?

Jacob


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Joachim Breitner | 7 Feb 2013 09:36
Picon
Favicon
Gravatar

Re: GHCi (7.4.2) is working on ARM

Hi,

that’s no surprise:
“ARM support in the RTS linker (#5839) has been implemented.”
(http://www.haskell.org/ghc/docs/7.4.2/html/users_guide/release-7-4-2.html)

Greetings,
Joachim

Am Mittwoch, den 06.02.2013, 18:21 -0500 schrieb dude:
> I have also validated ghc 7.4.1 on the Ubuntu Precise distro booted on
> a BeagleXM.
> 
> There's no ghci included.
> 
> --dude
> 
> On 02/06/2013 08:15 AM, kenny lu wrote:
> 
> > I've got a Cubieboard a few weeks back. I started it off with Linaro
> > (Ubuntu) 12.06.  
> > Today I started to upgrade the OS to 12.11, which surprisingly came
> > with ghc 7.4.2.
> > 
> > 
> > And ghci magically works too.
> > 
> > 
> > Here are the links
> > 
> > 
> > http://www.cubieboard.org
> > 
> > 
> > sudo apt-get install update-manager-core
> > sudo apt-get update
> > sudo apt-get upgrade
> > sudo do-release-upgrade
> > 
> > 
> > Regards,
> > Kenny
> > 
> > 
> > 
> > 
> > 
> > 
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe <at> haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 
> -- 
> dude
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

--

-- 
Joachim "nomeata" Breitner
Debian Developer
  nomeata <at> debian.org | ICQ# 74513189 | GPG-Keyid: 4743206C
  JID: nomeata <at> joachim-breitner.de | http://people.debian.org/~nomeata

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Doaitse Swierstra | 7 Feb 2013 13:58

Sol vingt simple problem in various languages and systems

At 

https://gist.github.com/ckirkendall/2934374 

you find solutions in many languages to a simple programming problem: the evaluation of an expression in an environment.

I want to point your attention to the currently last three entries:

  - one using the UUAGC compiler to solve the problem in an aspect oriented way (entered by Jeroen Bransen (jbransen))
  - one using some Haskell features, libraries and extensions (entered by me (doaitse))
  - one using our attribute grammar combinators from the AspectAG package, which expresses the 
    various aspects in an attribute grammar style (entered by Marcos Viera (marcosomarviera))

In case you did not manage to avoid getting wound up in a discussion about programming languages you can find
ammunition here.

 Doaitse
Ross Paterson | 7 Feb 2013 15:08
Picon
Favicon

arrow notation

I'd like to hear from anyone who's using arrow notation as supported by GHC,
because I'm planning a couple of changes to parts of it.
Harald Bögeholz | 7 Feb 2013 18:33
Picon

Re: Either example

Am 07.02.13 03:37, schrieb Jacob Thomas:
> Hello
> 
> I'm new to Haskell, and need help with figuring out the Either type...
> Any example to show how this works?

Maybe a program I wrote a while ago can help you get it.

https://github.com/ctbo/slitherlink

In Slitherlink.hs there is a function readProblem that can fail. It
returns either a String with an error message (Left) or the problem read
(Right).

[...]
readProblem :: String -> Either String Problem
readProblem s = do
            pl <- readProblemList s
            when (null pl) $ Left "Problem is empty."
            let columns = length $ head pl
            when (columns == 0) $ Left "Problem starts with an empty line."
            unless (all ((== columns) . length) pl) $ Left "Problem not
rectangular."
            let rows = length pl
            return $ listArray ((0, 0), (rows-1, columns-1)) $ concat pl
[...]

Or if you don't feel comfortable with using the Either monad, look at
the even simpler function readConstraint a few lines earlier in the same
file.

In the main solve.hs program this is used to output a meaningful error
message to the user if the input file is invalid:

[...]
  where work s n = case readProblem s of
             Left e -> putStrLn e
             Right p -> do
[...do something with the problem p...]

Hope this helps.

Harald

--

-- 
Harald Bögeholz    <bo <at> ct.de> (PGP key available from servers)
Redaktion c't      Tel.: +49 511 5352-300  Fax: +49 511 5352-417
                   http://www.ct.de/

                   int f[9814],b,c=9814,g,i;long a=1e4,d,e,h;
                   main(){for(;b=c,c-=14;i=printf("%04d",e+d/a),e=d%a)
                   while(g=--b*2)d=h*b+a*(i?f[b]:a/5),h=d/--g,f[b]=d%g;}
                                                          (Arndt/Haenel)

                   Affe Apfel Vergaser

/* Heise Zeitschriften Verlag GmbH & Co. KG * Karl-Wiechert-Allee 10 *
   30625 Hannover * Registergericht: Amtsgericht Hannover HRA 26709 *
   Persönlich haftende Gesellschafterin: Heise Zeitschriften Verlag *
   Geschäftsführung GmbH * Registergericht: Amtsgericht Hannover, HRB
   60405 * Geschäftsführer: Ansgar Heise, Dr. Alfons Schräder */
mukesh tiwari | 7 Feb 2013 19:05
Picon
Gravatar

Re: Either example

Hi Jocob
I would recommend you to go through the LYH ( http://learnyouahaskell.com/making-our-own-types-and-typeclasses ) .
data Either a b = Left a | Right b deriving (EqOrdReadShow

Lets say you have a division function and you want to avoid division by zero so this simple function
simpleDiv :: Int -> Int -> Int
simpleDiv m n = div m n

will through error and stop executing rest of you code ( See more on error handling ) so you can write your function which can handle this
 
division :: Int -> Int -> Either String Int
division m n
   | n == 0 = Left "Division by zero"
   | otherwise = Right  $ div m n

You can extend this solution as you wish and lets say you want both , some times integer division and some times floating point division based on flag. You set you flag true for floating division and false for integer division.

data Either' a b c = Left a | Mid b | Right c  deriving ( Show , Eq )

tempFunction :: Int -> Int -> Bool -> EIther' String Double Int
tempFunction m n f
   | n == 0 = Left "Division by zero"
   | f = Mid $ m / n  
   | otherwise = Right $ div m n

    
I haven't tested this code but the idea is if you want to return different  results then you use this. Also see Use of Either ( http://book.realworldhaskell.org/read/error-handling.html  ). Hopefully I have explained it correctly.

--Mukesh

On Thu, Feb 7, 2013 at 8:07 AM, Jacob Thomas <jthomas7 <at> ucsc.edu> wrote:

Hello 

I'm new to Haskell, and need help with figuring out the Either type...
Any example to show how this works?

Jacob


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Phil Freeman | 7 Feb 2013 21:45
Picon

Announce: LA Haskell User Group February Meeting

Dear Haskellers,
 
There will be a meeting of the LA Haskell User Group on Wednesday February 13th at 7pm. The details, including a list of discussion topics, as they become available, can be found here: http://www.meetup.com/Los-Angeles-Haskell-User-Group/events/102199892/
 
Thanks,
 
Phil Freeman.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Conal Elliott | 7 Feb 2013 23:49
Gravatar

Re: arrow notation

Hi Ross,

I make some use of arrow notation, though sadly I often have to avoid it because my (pseudo-)"arrows" don't have arr. I'd love to see a variant that has restricted expressiveness in exchange for arr-freeness.

-- Conal


On Thu, Feb 7, 2013 at 6:08 AM, Ross Paterson <ross <at> soi.city.ac.uk> wrote:
I'd like to hear from anyone who's using arrow notation as supported by GHC,
because I'm planning a couple of changes to parts of it.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Julian Blake Kongslie | 8 Feb 2013 00:02

Re: arrow notation

On Thu, Feb 07, 2013 at 02:49:40PM -0800, Conal Elliott wrote:
> Hi Ross,
> 
> I make some use of arrow notation, though sadly I often have to avoid it
> because my (pseudo-)"arrows" don't have arr. I'd love to see a variant that
> has restricted expressiveness in exchange for arr-freeness.

Are you familiar with Adam Megacz's "Generalized Arrows" work?
  http://www.cs.berkeley.edu/~megacz/garrows/

(I, too, would love to see Arrows-without-arr in Haskell)

> -- Conal

--

-- 
-Julian Blake Kongslie <jblake <at> omgwallhack.org>
If this is a mailing list, please CC me on replies.

vim: set ft=text :
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane