
I've got this import Data.Tuple fswp :: (a, b) -> (b, a) fswp = Data.Tuple.swap and get this • No instance for (Show ((a0, b0) -> (b0, a0))) arising from a use of ‘print’ (maybe you haven't applied a function to enough arguments?) • In a stmt of an interactive GHCi command: print it Not sure why or what to do to correct it. ⨽ Lawrence Bottorff Grand Marais, MN, USA borgauf@gmail.com

Hi Lawrence, it seems that you are trying to print your defined function. Most likely you just forgot to apply an argument to fswp. So 'fswp (1,2)' should just work fine. Cheers, Tobias On 9/9/21 11:25 PM, Galaxy Being wrote:
I've got this
import Data.Tuple fswp :: (a, b) -> (b, a) fswp = Data.Tuple.swap
and get this
• No instance for (Show ((a0, b0) -> (b0, a0))) arising from a use of ‘print’ (maybe you haven't applied a function to enough arguments?) • In a stmt of an interactive GHCi command: print it
Not sure why or what to do to correct it.
⨽ Lawrence Bottorff Grand Marais, MN, USA borgauf@gmail.com mailto:borgauf@gmail.com
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Hi Lawrence. Other people have given some answers, but perhaps saying it in a different way may also help. For starters, we have to remember that functions do not have instances of `Show' [1]: To exemplify, if we have a function and try to print it, we get an error: f :: a -> a f x = x $ ghci Prelude> :load fn.hs *Main> f <interactive>:2:1: error: • No instance for (Show (a0 -> a0)) arising from a use of ‘print’ (maybe you haven't applied a function to enough arguments?) • In a stmt of an interactive GHCi command: print it *Main> This is just to exemplify that there is nothing wrong with *your* function. As you see, I produced the same error with a much simpler function. So, as others mentioned, it looks like you just tried to print your function, which is not possible. I would also like to add a note about emacs haskell-mode's REPL that is related to this topic. haskell-mode's REPL runs `:type' behind the scenes when we try to print functions. It might give the impression that we can actually print functions, or that functions have instance of `Show', which is not the case. In emacs + haskell-mode, the variable haskell-interactive-types-for-show-ambiguous is supposed to be `t' by default (instead of `nil'). In any case, you can play with it and try to print functions directly by just typing their name [2]: (custom-set-variables '(haskell-interactive-types-for-show-ambiguous t) References: • [1] https://wiki.haskell.org/Show_instance_for_functions • [2] https://haskell.github.io/haskell-mode/manual/latest/Interactive-Haskell.htm... On Thu, Sep 09, 2021 at 04:25:58PM -0500, Galaxy Being wrote:
I've got this
import Data.Tuple fswp :: (a, b) -> (b, a) fswp = Data.Tuple.swap
and get this
• No instance for (Show ((a0, b0) -> (b0, a0))) arising from a use of ‘print’ (maybe you haven't applied a function to enough arguments?) • In a stmt of an interactive GHCi command: print it
Not sure why or what to do to correct it.
⨽ Lawrence Bottorff Grand Marais, MN, USA borgauf@gmail.com
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Hi, This isn’t homework! I’ve been staring at this for several hours - and that usually works. I also tried typed holes to no avail. I thinks it is quite simple really but I’ve gone past seeing it! I have data Expr a = Var a | Add (Expr a) (Expr a) and would like to write convert :: Expr (Maybe a) -> Maybe (Expr a) 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

I can't actually cheok right now,
but
```
convert (Var mv) = do
v <- mv
return $ Var v
```
is the "do notation" which should work.
(and similarly for the other expression)
On Thu, Nov 25, 2021, 19:13 mike h
Hi, This isn’t homework! I’ve been staring at this for several hours - and that usually works. I also tried typed holes to no avail. I thinks it is quite simple really but I’ve gone past seeing it!
I have data Expr a = Var a | Add (Expr a) (Expr a)
and would like to write
convert :: Expr (Maybe a) -> Maybe (Expr a)
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

convert (Var mx) = mx >>= (return .Var x)
Should also be the non-do-notation.
(again, typing from a phone, and not tested)
On Thu, Nov 25, 2021, 19:46 יהושע ולך
I can't actually cheok right now, but ``` convert (Var mv) = do v <- mv return $ Var v ```
is the "do notation" which should work. (and similarly for the other expression)
On Thu, Nov 25, 2021, 19:13 mike h
wrote: Hi, This isn’t homework! I’ve been staring at this for several hours - and that usually works. I also tried typed holes to no avail. I thinks it is quite simple really but I’ve gone past seeing it!
I have data Expr a = Var a | Add (Expr a) (Expr a)
and would like to write
convert :: Expr (Maybe a) -> Maybe (Expr a)
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

convert (Var mx) = mx >>= (return .Var)
Typo.
On Thu, Nov 25, 2021, 19:53 יהושע ולך
convert (Var mx) = mx >>= (return .Var x)
Should also be the non-do-notation. (again, typing from a phone, and not tested)
On Thu, Nov 25, 2021, 19:46 יהושע ולך
wrote: I can't actually cheok right now, but ``` convert (Var mv) = do v <- mv return $ Var v ```
is the "do notation" which should work. (and similarly for the other expression)
On Thu, Nov 25, 2021, 19:13 mike h
wrote: Hi, This isn’t homework! I’ve been staring at this for several hours - and that usually works. I also tried typed holes to no avail. I thinks it is quite simple really but I’ve gone past seeing it!
I have data Expr a = Var a | Add (Expr a) (Expr a)
and would like to write
convert :: Expr (Maybe a) -> Maybe (Expr a)
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

Or you could derive Traversable for Expr
Then sequenceA can be used:
https://hoogle.haskell.org/?hoogle=f%20(m%20a)%20-%3E%20m%20(f%20a)
On Thu 25 Nov 2021, 19:54 יהושע ולך,
convert (Var mx) = mx >>= (return .Var x)
Should also be the non-do-notation. (again, typing from a phone, and not tested)
On Thu, Nov 25, 2021, 19:46 יהושע ולך
wrote: I can't actually cheok right now, but ``` convert (Var mv) = do v <- mv return $ Var v ```
is the "do notation" which should work. (and similarly for the other expression)
On Thu, Nov 25, 2021, 19:13 mike h
wrote: Hi, This isn’t homework! I’ve been staring at this for several hours - and that usually works. I also tried typed holes to no avail. I thinks it is quite simple really but I’ve gone past seeing it!
I have data Expr a = Var a | Add (Expr a) (Expr a)
and would like to write
convert :: Expr (Maybe a) -> Maybe (Expr a)
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
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Hi Mike,
On Fri, Nov 26, 2021 at 12:12 AM mike h
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

Hi Mike,
An applicative instance of `Maybe` is enough to write the convert function you're looking for. Applicative is very useful when there are no dependencies between different branches, like when converting `Add`. But anyway, converting between applicative and monadic operations is a good exercise, which I'll leave for you. It's always possible to convert from applicative to monadic form, but the more useful conversion is from monadic to applicative (which is not always possible):
```
convert :: Expr (Maybe a) -> Maybe (Expr a)
convert (Var a) = Var <$> a
convert (Add a b) = Add <$> convert a
<*> convert b
```
Best regards,
Marcin
Sent with ProtonMail Secure Email.
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Thursday, November 25th, 2021 at 18:10, mike h
Hi,
This isn’t homework! I’ve been staring at this for several hours - and that usually works.
I also tried typed holes to no avail. I thinks it is quite simple really but I’ve gone past seeing it!
I have
data Expr a = Var a | Add (Expr a) (Expr a)
and would like to write
convert :: Expr (Maybe a) -> Maybe (Expr a)
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
participants (9)
-
coot@coot.me
-
Fernando Basso
-
Francesco Ariis
-
Galaxy Being
-
Imants Cekusins
-
Kim-Ee Yeoh
-
mike h
-
Tobias Brandt
-
יהושע ולך