Created
May 16, 2016 18:44
-
-
Save j1r1k/7ccc3e0996295370b8965c0f3c882577 to your computer and use it in GitHub Desktop.
PureScript by Example: Chapter 10 (The Foreign Function Interface) exercise 10.19.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Tree where | |
import Prelude | |
import Control.Alt | |
import Data.Either | |
import Data.Foreign | |
import Data.Foreign.Class | |
data Tree a = Leaf a | Branch (Tree a) (Tree a) | |
instance treeIsForeign :: (IsForeign a) => IsForeign (Tree a) where | |
read value = (Branch <$> readProp "left" value <*> readProp "right" value) | |
<|> (Leaf <$> readProp "value" value) | |
instance showTree :: (Show a) => Show (Tree a) where | |
show (Branch l r) = "Tree Left [ " ++ show l ++ " ] Right [ " ++ show r ++ "]" | |
show (Leaf a) = "Leaf " ++ show a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment