Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/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.  Returning Maybe Float -> Float -> Float (Olivier Duhart)
   2. Re:  Returning Maybe Float -> Float -> Float (Ulrik Rasmussen)
   3. Re:  Returning Maybe Float -> Float -> Float (Olivier Duhart)
   4. Re:  Returning Maybe Float -> Float -> Float (David McBride)


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

Message: 1
Date: Mon, 08 Feb 2016 13:54:43 +0000
From: Olivier Duhart <olivier.duh...@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] Returning Maybe Float -> Float -> Float
Message-ID:
        <CAHt0UWWGPOOwxkJCYKVKjMHV=kl6ujhx-2yp343oz7bacrn...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

hello,

I am starting with Haskell and trying some little exercices on my own. I
successfully implemented a reverse polish notation evaluator and I want to
improve it a little using *Maybe*

All i want is to implement  a function that can returned available
functions according to its string name
i.e return (+) when gived "+"
I also want to return Nothing if the operation is not available (not
implemented yet).
So my function should Maybe return a (float -> float -> float)

My current implementation is

operation :: String -> Maybe Float -> Float -> Float
operation op
   | op == "+" = Just (+)
   | op == "-" = Just (-)
   | op == "*" = Just (*)
   | op == "/" = Just (/)
   | otherwise = Nothing


but it failed to compile with the following error :

rpn.hs:64:18:
    Couldn't match expected type `Maybe Float -> Float -> Float'
                with actual type `Maybe a0'
    In the expression: Nothing
    In an equation for `operation':
        operation op
          | op == "+" = Just (+)
          | op == "-" = Just (-)
          | op == "*" = Just (*)
          | op == "/" = Just (/)
          | otherwise = Nothing


I don't understand the error :( Do I have to explicitly type the Nothing
return ?

Could you guide me to a solution or explain me what I am doing wrong,
please ?

Thanks in advance

Olivier
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160208/ffd5fb06/attachment-0001.html>

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

Message: 2
Date: Mon, 8 Feb 2016 15:07:40 +0100
From: Ulrik Rasmussen <hask...@utr.dk>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Returning Maybe Float -> Float ->
        Float
Message-ID: <56b8a12c.9080...@utr.dk>
Content-Type: text/plain; charset=windows-1252; format=flowed

On 2016-02-08 14:54, Olivier Duhart wrote:
> hello,
>
> I am starting with Haskell and trying some little exercices on my own. I
> successfully implemented a reverse polish notation evaluator and I want
> to improve it a little using *Maybe*
> *
> *
> All i want is to implement  a function that can returned available
> functions according to its string name
> i.e return (+) when gived "+"
> I also want to return Nothing if the operation is not available (not
> implemented yet).
> So my function should Maybe return a (float -> float -> float)
>
> My current implementation is
>
>     operation :: String -> Maybe Float -> Float -> Float
>     operation op
>         | op == "+" = Just (+)
>         | op == "-" = Just (-)
>         | op == "*" = Just (*)
>         | op == "/" = Just (/)
>         | otherwise = Nothing
>
>
> but it failed to compile with the following error :
>
> rpn.hs:64:18:
>      Couldn't match expected type `Maybe Float -> Float -> Float'
>                  with actual type `Maybe a0'
>      In the expression: Nothing
>      In an equation for `operation':
>          operation op
>            | op == "+" = Just (+)
>            | op == "-" = Just (-)
>            | op == "*" = Just (*)
>            | op == "/" = Just (/)
>            | otherwise = Nothing
>
>
> I don't understand the error :( Do I have to explicitly type the Nothing
> return ?
>
> Could you guide me to a solution or explain me what I am doing wrong,
> please ?
>
> Thanks in advance
>
> Olivier

Hi,

The type String -> Maybe Float -> Float -> Float parenthesizes as

    String -> (Maybe Float) -> Float -> Float,

but I think you meant

    String -> Maybe (Float -> Float -> Float)


/Ulrik


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

Message: 3
Date: Mon, 08 Feb 2016 14:14:44 +0000
From: Olivier Duhart <olivier.duh...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Returning Maybe Float -> Float ->
        Float
Message-ID:
        <CAHt0UWVg49mOt35wRuq=ZMYpUs3DqGP8wCcV1c=fth6kogy...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

thanks Ulrik,

it solves the compilation problem. But now  I have an execution error (with
GHCi) :

*Main> (operation "+") 2.0 2.0

<interactive>:3:1:
    Couldn't match expected type `Double -> Double -> t'
                with actual type `Maybe (Float -> Float -> Float)'
    Relevant bindings include it :: t (bound at <interactive>:3:1)
    The function `operation' is applied to three arguments,
    but its type `String -> Maybe (Float -> Float -> Float)'
    has only one
    In the expression: (operation "+") 2.0 2.0
    In an equation for `it': it = (operation "+") 2.0 2.0

As I understand it ghci guess that the two 2.0 parameters to my (operation
"+") are Double and the function returned by operation expects Float
instead, How to solve this ?

I tried to replace every  Float with Double in my .hs file but still there
is a problem

*Main> (operation "+") 2.0 2.0

<interactive>:3:1:
    Couldn't match expected type `Double -> Double -> t'
                with actual type `Maybe (Double -> Double -> Double)'
    Relevant bindings include it :: t (bound at <interactive>:3:1)
    The function `operation' is applied to three arguments,
    but its type `String -> Maybe (Double -> Double -> Double)'
    has only one
    In the expression: (operation "+") 2.0 2.0
    In an equation for `it': it = (operation "+") 2.0 2.0

Could you explain me what is the -> t at the end of the expected type ?



Le lun. 8 f?vr. 2016 ? 15:07, Ulrik Rasmussen <hask...@utr.dk> a ?crit :

> On 2016-02-08 14:54, Olivier Duhart wrote:
> > hello,
> >
> > I am starting with Haskell and trying some little exercices on my own. I
> > successfully implemented a reverse polish notation evaluator and I want
> > to improve it a little using *Maybe*
> > *
> > *
> > All i want is to implement  a function that can returned available
> > functions according to its string name
> > i.e return (+) when gived "+"
> > I also want to return Nothing if the operation is not available (not
> > implemented yet).
> > So my function should Maybe return a (float -> float -> float)
> >
> > My current implementation is
> >
> >     operation :: String -> Maybe Float -> Float -> Float
> >     operation op
> >         | op == "+" = Just (+)
> >         | op == "-" = Just (-)
> >         | op == "*" = Just (*)
> >         | op == "/" = Just (/)
> >         | otherwise = Nothing
> >
> >
> > but it failed to compile with the following error :
> >
> > rpn.hs:64:18:
> >      Couldn't match expected type `Maybe Float -> Float -> Float'
> >                  with actual type `Maybe a0'
> >      In the expression: Nothing
> >      In an equation for `operation':
> >          operation op
> >            | op == "+" = Just (+)
> >            | op == "-" = Just (-)
> >            | op == "*" = Just (*)
> >            | op == "/" = Just (/)
> >            | otherwise = Nothing
> >
> >
> > I don't understand the error :( Do I have to explicitly type the Nothing
> > return ?
> >
> > Could you guide me to a solution or explain me what I am doing wrong,
> > please ?
> >
> > Thanks in advance
> >
> > Olivier
>
> Hi,
>
> The type String -> Maybe Float -> Float -> Float parenthesizes as
>
>     String -> (Maybe Float) -> Float -> Float,
>
> but I think you meant
>
>     String -> Maybe (Float -> Float -> Float)
>
>
> /Ulrik
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160208/65e09e62/attachment-0001.html>

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

Message: 4
Date: Mon, 8 Feb 2016 09:21:52 -0500
From: David McBride <toa...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Returning Maybe Float -> Float ->
        Float
Message-ID:
        <can+tr42xp6tlwe78ulcztijsdzu1cnjh1djrb-ov+slbf+c...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

You need to test to see whether you have a valid operation before you can
input the 2.0's.  Try this:

main = do
  x <- getLine
  putStrLn $ case operation x of
    Nothing -> "Got nothing."
    Just op -> show $ op 2.0 2.0


On Mon, Feb 8, 2016 at 9:14 AM, Olivier Duhart <olivier.duh...@gmail.com>
wrote:

> thanks Ulrik,
>
> it solves the compilation problem. But now  I have an execution error
> (with GHCi) :
>
> *Main> (operation "+") 2.0 2.0
>
> <interactive>:3:1:
>     Couldn't match expected type `Double -> Double -> t'
>                 with actual type `Maybe (Float -> Float -> Float)'
>     Relevant bindings include it :: t (bound at <interactive>:3:1)
>     The function `operation' is applied to three arguments,
>     but its type `String -> Maybe (Float -> Float -> Float)'
>     has only one
>     In the expression: (operation "+") 2.0 2.0
>     In an equation for `it': it = (operation "+") 2.0 2.0
>
> As I understand it ghci guess that the two 2.0 parameters to my (operation
> "+") are Double and the function returned by operation expects Float
> instead, How to solve this ?
>
> I tried to replace every  Float with Double in my .hs file but still there
> is a problem
>
> *Main> (operation "+") 2.0 2.0
>
> <interactive>:3:1:
>     Couldn't match expected type `Double -> Double -> t'
>                 with actual type `Maybe (Double -> Double -> Double)'
>     Relevant bindings include it :: t (bound at <interactive>:3:1)
>     The function `operation' is applied to three arguments,
>     but its type `String -> Maybe (Double -> Double -> Double)'
>     has only one
>     In the expression: (operation "+") 2.0 2.0
>     In an equation for `it': it = (operation "+") 2.0 2.0
>
> Could you explain me what is the -> t at the end of the expected type ?
>
>
>
> Le lun. 8 f?vr. 2016 ? 15:07, Ulrik Rasmussen <hask...@utr.dk> a ?crit :
>
>> On 2016-02-08 14:54, Olivier Duhart wrote:
>> > hello,
>> >
>> > I am starting with Haskell and trying some little exercices on my own. I
>> > successfully implemented a reverse polish notation evaluator and I want
>> > to improve it a little using *Maybe*
>> > *
>> > *
>> > All i want is to implement  a function that can returned available
>> > functions according to its string name
>> > i.e return (+) when gived "+"
>> > I also want to return Nothing if the operation is not available (not
>> > implemented yet).
>> > So my function should Maybe return a (float -> float -> float)
>> >
>> > My current implementation is
>> >
>> >     operation :: String -> Maybe Float -> Float -> Float
>> >     operation op
>> >         | op == "+" = Just (+)
>> >         | op == "-" = Just (-)
>> >         | op == "*" = Just (*)
>> >         | op == "/" = Just (/)
>> >         | otherwise = Nothing
>> >
>> >
>> > but it failed to compile with the following error :
>> >
>> > rpn.hs:64:18:
>> >      Couldn't match expected type `Maybe Float -> Float -> Float'
>> >                  with actual type `Maybe a0'
>> >      In the expression: Nothing
>> >      In an equation for `operation':
>> >          operation op
>> >            | op == "+" = Just (+)
>> >            | op == "-" = Just (-)
>> >            | op == "*" = Just (*)
>> >            | op == "/" = Just (/)
>> >            | otherwise = Nothing
>> >
>> >
>> > I don't understand the error :( Do I have to explicitly type the Nothing
>> > return ?
>> >
>> > Could you guide me to a solution or explain me what I am doing wrong,
>> > please ?
>> >
>> > Thanks in advance
>> >
>> > Olivier
>>
>> Hi,
>>
>> The type String -> Maybe Float -> Float -> Float parenthesizes as
>>
>>     String -> (Maybe Float) -> Float -> Float,
>>
>> but I think you meant
>>
>>     String -> Maybe (Float -> Float -> Float)
>>
>>
>> /Ulrik
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160208/7beeda76/attachment.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 92, Issue 10
*****************************************

Reply via email to