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. Re: Confusing Show/print error (Fernando Basso) ---------------------------------------------------------------------- Message: 1 Date: Sun, 12 Sep 2021 07:57:38 -0300 From: Fernando Basso <fernandobasso...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Confusing Show/print error Message-ID: <20210912105738.egomltlkquv5l...@gmail.com> Content-Type: text/plain; charset=utf-8 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.html#Type-of-expressions 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 > borg...@gmail.com > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 158, Issue 2 *****************************************