-
Notifications
You must be signed in to change notification settings - Fork 14
Added extra files to Haskell directory #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
@MitchStevens Hey, that's really nice! I would suggest a small change, though.
You can amend the commits and do a force push |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code can be simplified a lot. In the end you just have:
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
module TransformBST where
import Data.Traversable (mapAccumR)
data Tree a = Branch (Tree a) a (Tree a) | Bud
deriving (Show, Functor, Foldable, Traversable)
transformBST :: Num a => Tree a -> Tree a
transformBST = snd . mapAccumR (\a b -> (a + b, a)) 0
data Tree a = Branch (Tree a) a (Tree a) | Bud | ||
deriving (Show) | ||
|
||
instance Functor Tree where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be derived by DeriveFunctor
go (Branch l v r) = Branch (go l) (f v) (go r) | ||
go Bud = Bud | ||
|
||
instance Foldable Tree where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be derived by DeriveFoldable
go (Branch l v r) = go l <> f v <> go r | ||
go Bud = mempty | ||
|
||
instance Traversable Tree where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be derived by DeriveTraversable
eee59be
to
9452685
Compare
Added solutions to the transformerBST problem (which has a really nice solution in haskell) and the dice problem. Will add documentation and tests soon. Might also be a good idea to run
cabal init
and make this collection of files a single project, like in the Scala and Closure sections.