<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif;font-size:16px"><div id="yui_3_16_0_1_1441719924602_11728"><span id="yui_3_16_0_1_1441719924602_11743">Thanks I'll work through it.</span></div><div id="yui_3_16_0_1_1441719924602_11795"><br><span id="yui_3_16_0_1_1441719924602_11743"></span></div><div id="yui_3_16_0_1_1441719924602_11796"><span id="yui_3_16_0_1_1441719924602_11743"></span></div> <br><div class="qtdSeparateBR"><br><br></div><div style="display: block;" class="yahoo_quoted"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif; font-size: 16px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif; font-size: 16px;"> <div dir="ltr"> <font face="Arial" size="2"> On Tuesday, 8 September 2015, 0:39, Imants Cekusins <imantc@gmail.com> wrote:<br> </font> </div> <br><br> <div class="y_msg_container">> data Tree a = Node a [Tree a]<br><br>well here is something that builds and runs. Not sure if the monad laws apply.<br>watch out for indents!<br><br><br>{-# LANGUAGE InstanceSigs #-}<br>module TreeApp where<br><br>import Debug.Trace<br>import Data.Char<br><br>data Tree a = Node a [Tree a] deriving (Show)<br><br><br>instance Functor Tree where<br> fmap::(a -> b) -> Tree a -> Tree b<br> fmap f (Node x l0) = Node (f x) (fmap f <$> l0)<br><br><br>instance Applicative Tree where<br> pure::a -> Tree a<br> pure a = Node a []<br><br> (<*>)::Tree (a -> b) -> Tree a -> Tree b<br> (<*>) (Node f _) tra = f <$> tra<br><br><br>instance Monad Tree where<br> return::a -> Tree a<br> return a = pure a<br><br> (>>=)::Tree a -> (a -> Tree b) -> Tree b<br> (>>=) (Node x []) amb = amb x<br> (>>=) (Node x l0) amb = Node b (m1 <$> l0)<br> where (Node b _) = amb x<br> m1 ta = ta >>= amb<br><br><br>f::Char->Int<br>f = digitToInt<br><br>mb::Char->Tree Int<br>mb c = f <$> (pure c)<br><br>main::Char -> Char -> IO ()<br>main a b = print $ tc4 >>= mb<br>{-<br> do<br> print ti2<br> print ta3<br> tm4 <- tc4<br>-}<br> where tc1 = pure a<br> ti2 = f <$> tc1<br> ta3 = (Node f []) <*> tc1<br> tc4 = Node b [tc1]<br>_______________________________________________<br>Beginners mailing list<br><a href="" class="removed-link" ymailto="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br><a href="" class="removed-link" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br><br><br></div> </div> </div> </div></div></body></html>