Skip to content

Conversation

MitchStevens
Copy link

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.

@ashwinbhaskar
Copy link
Owner

ashwinbhaskar commented May 18, 2019

@MitchStevens Hey, that's really nice! I would suggest a small change, though.

  1. Can you prepend your commit messages with [Haskell-Way] for consistency?
  2. Please remove the License file. We will add a single license file for the whole repo in the root.
  3. Remove the readme in haskell and append it to the README of the repo. The read me can be added to the readme of the repo.

You can amend the commits and do a force push

Copy link

@jvanbruegge jvanbruegge left a 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

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

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants