Hi Mike,

On Fri, Nov 26, 2021 at 12:12 AM mike h <mike_k_houghton@yahoo.co.uk> wrote:

I have
data Expr a = Var a | Add (Expr a) (Expr a)

and would like to write

convert :: Expr (Maybe a) -> Maybe (Expr a)

With the requisite setup, convert has a one word definition. But more on that later.

Yehoshua has already given you a nudge in the right direction. Others will surely chime in if you get stuck grinding out something the compiler will type check.

What we could discuss is higher level. Where would use this convert function? What utility could you obtain from it?




which returns Nothing if there is an occurrence of Nothing inside the
input expression e, otherwise it returns Just e', where e'
is a new expression where the internal values of type a are not wrapped in Just.
You should use the functionality of the Maybe monad to implement
the convert function.


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