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:  question about any (Brent Yorgey)
   2. Re:  question about any (Manfred Lotz)
   3. Re:  question about any (Manfred Lotz)
   4.  Better error messages (Peter Hall)
   5. Re:  Better error messages (Daniel Fischer)
   6. Re:  Better error messages (Chadda? Fouch?)
   7. Re:  Better error messages (Michael Orlitzky)
   8. Re:  question about any (Manfred Lotz)
   9. Re:  Better error messages (Peter Hall)
  10. Re:  The numeric type stack (Mike Meyer)
  11.  Amanda (Christiaan Kras)


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

Message: 1
Date: Thu, 29 Dec 2011 11:03:38 -0500
From: Brent Yorgey <byor...@seas.upenn.edu>
Subject: Re: [Haskell-beginners] question about any
To: beginners@haskell.org
Message-ID: <20111229160338.ga18...@seas.upenn.edu>
Content-Type: text/plain; charset=us-ascii

On Thu, Dec 29, 2011 at 06:45:27AM +0100, Manfred Lotz wrote:
> 
> or' :: Monad m => ( a -> m Bool) -> [a] -> [m Bool]
> or' _ [] = []
> or' p (x:xs) = p x : or' p xs
> 
> and' :: Monad m => ( a -> m Bool) -> [a] -> [m Bool]
> and' _ [] = []
> and' p (x:xs) = p x : and' p xs

Note that or' = and' = map.

-Brent



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

Message: 2
Date: Thu, 29 Dec 2011 20:54:14 +0100
From: Manfred Lotz <manfred.l...@arcor.de>
Subject: Re: [Haskell-beginners] question about any
To: beginners@haskell.org
Message-ID: <20111229205414.567a6...@arcor.com>
Content-Type: text/plain; charset=US-ASCII

On Thu, 29 Dec 2011 11:03:38 -0500
Brent Yorgey <byor...@seas.upenn.edu> wrote:

> On Thu, Dec 29, 2011 at 06:45:27AM +0100, Manfred Lotz wrote:
> > 
> > or' :: Monad m => ( a -> m Bool) -> [a] -> [m Bool]
> > or' _ [] = []
> > or' p (x:xs) = p x : or' p xs
> > 
> > and' :: Monad m => ( a -> m Bool) -> [a] -> [m Bool]
> > and' _ [] = []
> > and' p (x:xs) = p x : and' p xs
> 
> Note that or' = and' = map.
> 
> -Brent
> 

Thanks, Brent for pointing me to this. 

I guess I got it:

With or' = map I get

myany :: Monad m => (a -> m Bool) -> [a] -> m Bool
myany p = mor . map p

and with my former definition of mor I get:

myany p = liftM or . sequence . map p

and then:

myany p = liftM or . mapM p

which is Markus solution.



-- 
Manfred




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

Message: 3
Date: Thu, 29 Dec 2011 20:29:40 +0100
From: Manfred Lotz <manfred.l...@arcor.de>
Subject: Re: [Haskell-beginners] question about any
To: beginners@haskell.org
Message-ID: <20111229202940.61fe6...@arcor.com>
Content-Type: text/plain; charset=UTF-8

On Thu, 29 Dec 2011 12:14:30 +0200
Markus L?ll <markus.l...@gmail.com> wrote:

> You can use 'mapM' similar to 'map', to get the resultant list in the
> monad, and then liftM the function 'or' into it. This way you don't
> need to recurse explicitly, like in or' and and'.
> 
> many :: Monad m => (a -> m Bool) -> [a] -> m Bool
> many p list = or `liftM` mapM p list
> 
> (Type of mapM is: Monad m => (a -> m b) -> [a] -> m [b])
> 
> On Thu, Dec 29, 2011 at 7:45 AM, Manfred Lotz <manfred.l...@arcor.de>

This is indeed much easier and clearer.

-- 
Thanks,
Manfred





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

Message: 4
Date: Thu, 29 Dec 2011 20:25:31 +0000
From: Peter Hall <peter.h...@memorphic.com>
Subject: [Haskell-beginners] Better error messages
To: beginners@haskell.org
Message-ID:
        <CAA6hAk4wpDXYU3KbZoToa95XD37oVDqXQw=ks4xU=b5unau...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

If I have something like this

main = do
    args <- getArgs
    let file = args !! 0
    -- etc...


And I run it without any arguments, I get an error message like this:
"Prelude.(!!): index too large".

What's the best way to handle an error like this to give a better
message back to the user?


Peter



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

Message: 5
Date: Thu, 29 Dec 2011 21:42:59 +0100
From: Daniel Fischer <daniel.is.fisc...@googlemail.com>
Subject: Re: [Haskell-beginners] Better error messages
To: beginners@haskell.org, peter.h...@memorphic.com
Message-ID: <201112292142.59736.daniel.is.fisc...@googlemail.com>
Content-Type: Text/Plain;  charset="iso-8859-1"

On Thursday 29 December 2011, 21:25:31, Peter Hall wrote:
> If I have something like this
> 
> main = do
>     args <- getArgs
>     let file = args !! 0
>     -- etc...
> 
> 
> And I run it without any arguments, I get an error message like this:
> "Prelude.(!!): index too large".
> 
> What's the best way to handle an error like this to give a better
> message back to the user?

main = do
    args <- getArgs
    case args of
      [] -> complain
      _ -> happiness

or

    args <- getArgs
    if null args
      then complain
      else happiness



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

Message: 6
Date: Thu, 29 Dec 2011 21:43:40 +0100
From: Chadda? Fouch? <chaddai.fou...@gmail.com>
Subject: Re: [Haskell-beginners] Better error messages
To: peter.h...@memorphic.com
Cc: beginners@haskell.org
Message-ID:
        <CANfjZRYzupk33sTvy85HsoqBBiF4D=7ydekxoi2h0er545t...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Thu, Dec 29, 2011 at 9:25 PM, Peter Hall <peter.h...@memorphic.com> wrote:
> If I have something like this
>
> main = do
> ? ?args <- getArgs
> ? ?let file = args !! 0
> ? ?-- etc...
>
>
> And I run it without any arguments, I get an error message like this:
> "Prelude.(!!): index too large".
>
> What's the best way to handle an error like this to give a better
> message back to the user?

Don't use partial functions (functions that can fail on some input)
except if you're sure they won't fail (and even then you may be better
off not using them...), here you can use pattern matching :

> main = do
>    args <- getArgs
>    case args of
>      [file] -> -- etc
>      _ -> error "You should call this program with one file argument !!"

In this particular case (arguments parsing), if you ever find yourself
with more complicated argument handling to do, consider using one of
the good packages that make this easy and safe to do like cmdargs.

-- 
Jeda?



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

Message: 7
Date: Thu, 29 Dec 2011 15:57:47 -0500
From: Michael Orlitzky <mich...@orlitzky.com>
Subject: Re: [Haskell-beginners] Better error messages
To: beginners@haskell.org
Message-ID: <4efcd44b.5050...@orlitzky.com>
Content-Type: text/plain; charset=ISO-8859-1

On 12/29/11 15:42, Daniel Fischer wrote:
> On Thursday 29 December 2011, 21:25:31, Peter Hall wrote:
>> If I have something like this
>>
>> main = do
>>     args <- getArgs
>>     let file = args !! 0
>>     -- etc...
>>
>>
>> And I run it without any arguments, I get an error message like this:
>> "Prelude.(!!): index too large".
>>
>> What's the best way to handle an error like this to give a better
>> message back to the user?
> 
> main = do
>     args <- getArgs
>     case args of
>       [] -> complain
>       _ -> happiness
> 
> or
> 
>     args <- getArgs
>     if null args
>       then complain
>       else happiness

I've always used Control.Monad.when here, to avoid unnecessary nesting
(or the alternative "do nothing"). E.g,

  main = do
    args <- getArgs
    when (null args) $ do
      putStrLn help_text
      exitWith $ ExitFailure exit_not_enough_args





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

Message: 8
Date: Thu, 29 Dec 2011 21:06:29 +0100
From: Manfred Lotz <manfred.l...@arcor.de>
Subject: Re: [Haskell-beginners] question about any
To: beginners@haskell.org
Message-ID: <20111229210629.1c643...@arcor.com>
Content-Type: text/plain; charset=US-ASCII

On Thu, 29 Dec 2011 08:29:41 +0100
Tim Baumgartner <baumgartner....@googlemail.com> wrote:


> >
> 
> Hi Manfred,
> 
> have a look here:
> http://hackage.haskell.org/packages/archive/monad-loops/latest/doc/html/Control-Monad-Loops.html#v:allM
> 

Thanks Tim, didn't know that.


-- 
Manfred




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

Message: 9
Date: Thu, 29 Dec 2011 22:00:05 +0000
From: Peter Hall <peter.h...@memorphic.com>
Subject: Re: [Haskell-beginners] Better error messages
To: beginners@haskell.org
Message-ID:
        <CAA6hAk5YGr-4eszL=MqZak-vE_LcT+Xj7RZSQ1pLPZ=yiar...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Thanks,
I was trying this, but it turns out my indentation was wrong; the
'then' and 'else' need to be indented under the 'if', or else it gets
confused about the do block.

Also thanks for the other solutions. I'm looking up cmdargs now.

Peter


On Thu, Dec 29, 2011 at 8:42 PM, Daniel Fischer
<daniel.is.fisc...@googlemail.com> wrote:
> On Thursday 29 December 2011, 21:25:31, Peter Hall wrote:
>> If I have something like this
>>
>> main = do
>> ? ? args <- getArgs
>> ? ? let file = args !! 0
>> ? ? -- etc...
>>
>>
>> And I run it without any arguments, I get an error message like this:
>> "Prelude.(!!): index too large".
>>
>> What's the best way to handle an error like this to give a better
>> message back to the user?
>
> main = do
> ? ?args <- getArgs
> ? ?case args of
> ? ? ?[] -> complain
> ? ? ?_ -> happiness
>
> or
>
> ? ?args <- getArgs
> ? ?if null args
> ? ? ?then complain
> ? ? ?else happiness



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

Message: 10
Date: Thu, 29 Dec 2011 15:04:26 -0800
From: Mike Meyer <m...@mired.org>
Subject: Re: [Haskell-beginners] The numeric type stack
To: beginners <beginners@haskell.org>
Message-ID: <20111229150426.7ba59...@bhuda.mired.org>
Content-Type: text/plain; charset=US-ASCII

 On Thu, 29 Dec 2011 04:49:53 -0500
Brandon Allbery <allber...@gmail.com> wrote:
> On Thu, Dec 29, 2011 at 00:33, Mike Meyer <m...@mired.org> wrote:
> > So, is there a reasonable way to get the value of two Integral types
> > divided by each other and rounded? How about one integral type and one
> > RealFrac? I know I can get it truncated towards either 0 or negative
> > infinity, but that's not what I want here.
> You have two options:
> (1) use fromIntegral to coerce an Integral value to a RealFrac;

Yup. that's what I did.

> (2) use (div) (division on Integrals) instead of (/).

Not an option, because div doesn't round, it truncates. Figuring out
whether to add one to get it to round would be a lot messier than just
using fromIntegral.

The other half of this is that one of the two values is computed from
constants in the code. So the code works if I don't coerce it. But all
the computation for that value is done using floats.

Seems like a violation of POLA to me.

      <mike
-- 
Mike Meyer <m...@mired.org>             http://www.mired.org/
Independent Software developer/SCM consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org



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

Message: 11
Date: Fri, 30 Dec 2011 00:17:04 +0100
From: Christiaan Kras <c.k...@pcc-online.net>
Subject: [Haskell-beginners] Amanda
To: beginners@haskell.org
Message-ID: <4efcf4f0.8030...@pcc-online.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hello list,

First time I'm posting here. I've been interested in Haskell for about a 
year now, but sadly haven't done too much with it yet.

I decided to get my bachelors degree in Computer Science/Engineering 
(it's a bit of a mixed course at my university) after having worked for 
over 4.5 years. One of the classes I've got to follow is discrete math.

A first glimpse on the study material made me think "Cool! They're using 
Haskell!". This is however not the case. Instead, we're using Amanda.

Amanda was written by Dick Bruin, who as far as I know used to teach at 
my university, but has now moved on to another university. I was told 
Amanda was being used at my university, NHL Leeuwarden (Netherlands) and 
the University of Twente (Netherlands). (strictly my university isn't a 
university, but high school means something different in English than it 
does in Dutch :-))

The reason I'm posting here is because Amanda seems extremely heavily 
influenced by Haskell. I think it was written in either Delphi or 
Pascal, but I've got to verify that with one of the teachers.

It's quite old as well, as it was developed between 1990 and 2000.

A lot of stuff written in Amanda can easily be converted to Haskell with 
a few small changes. Which makes me wonder why they aren't using Haskell 
now. List comprehensions use the same syntax, but use a semicolon 
instead of a comma for separating generators and terms. Operators such 
as +,/,* etc. are functions, just like they are in Haskell. For what I 
can tell Amanda is more or less a stripped down version of Haskell.

The thing I was wondering though, is if anyone on this list has ever 
heard of Amanda before. If so, where did you got in contact with it?

-- 
Christiaan Kras
http://blog.htbaa.com



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

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


End of Beginners Digest, Vol 42, Issue 32
*****************************************

Reply via email to