
It seems to me like there might be benefit to special casing the error
message when (as in this case) the only thing wrong with an expression
is that the resulting type is missing the Show instance implicitly
demanded by ghci.
On Sun, Dec 20, 2015 at 4:06 AM, Lorenzo Isella
On Thu, Dec 17, 2015 at 12:10:01PM +0100, Henk-Jan van Tuyl wrote:
On Thu, 17 Dec 2015 11:37:24 +0100, Lorenzo Isella
wrote: : data Rose a = a :> [Rose a] deriving (Eq, Show)
and the root can be detected simply as
root (a :> rs) = a
I would like to have the expression (with the ":>" notation for the Node) of the function to find the children of the root. Example of expected behavior of this function children
children (1 :> [2 :> [], 3 :> []]) = [2 :> [], 3 :> []]
On top of that, I am trying to get the functions to have the functions
size :: Rose a -> Int leaves :: Rose a -> Int
that count the number of nodes in a rose tree, respectively the number of leaves (nodes without any children). For the children function, I have tried stuff like
children (a :> rs) = rs
quite unsuccessfully.
:
Your definition of children is correct, what is the message you get from the compiler/interpreter?
Regards, Henk-Jan van Tuyl
Hello, This is the situation: my script rose.hs is given by
data Rose a = a :> [Rose a]
root (a :> rs) = a
children (a :> rs) = rs
and this is what happens when I load it and apply the children function on a rose tree
$ ghci GHCi, version 7.8.4: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> :load rose.hs [1 of 1] Compiling Main ( rose.hs, interpreted ) Ok, modules loaded: Main. *Main> children (1 :> [2 :> [], 3 :> []])
<interactive>:3:1: No instance for (Show (Rose t0)) arising from a use of ‘print’ In a stmt of an interactive GHCi command: print it
I do not really understand what goes wrong and any suggestion is appreciated. Cheers
Lorenzo
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners