Skip to content

Commit

Permalink
Moved the showIndent method to writer and removed redundant files
Browse files Browse the repository at this point in the history
  • Loading branch information
davebarda committed Sep 21, 2016
1 parent 55e282d commit 7a1fc48
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
5 changes: 0 additions & 5 deletions OnlineLearner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Label
import Writer
import Loss
import Data.Matrix
import Data.String.Utils

-- Example represents the examples that online learners can receive
type Example = Matrix Double
Expand All @@ -22,10 +21,6 @@ data TrainingKnowledge = EllipsoidKnowledge {
w:: Matrix Double
} deriving Eq

-- Adds indentation to the Show instance of the given object
showIndent :: (Show a) => a -> String
showIndent obj = "\t" ++ replace "\n" "\n\t" (show obj)

instance Show TrainingKnowledge where
show (EllipsoidKnowledge d eta' a' w') = "EllipsoidKnowledge with parameters: " ++
"\n\tdimension: " ++ show d ++ "\n\teta: " ++ show eta' ++ "\n\tw:\n\t" ++
Expand Down
10 changes: 7 additions & 3 deletions Writer.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Writer (Writer(..), DiffList(..), tell, toDiffList, fromDiffList, getValFromWriter) where
module Writer (Writer(..), DiffList(..), tell, toDiffList, fromDiffList, getValFromWriter, showIndent) where
import Control.Monad (liftM, ap)
import Data.String.Utils

-- Writer data type represents a log writer
newtype Writer w a = Writer { runWriter :: (a, w) }
Expand All @@ -20,12 +21,10 @@ instance (Monoid w) => Monad (Writer w) where
return x = Writer (x, mempty)
(Writer (x, v)) >>= f = let (Writer (y, v')) = f x in Writer (y, v `mappend` v')


instance Monoid (DiffList a) where
mempty = DiffList (\xs -> [] ++ xs)
(DiffList f) `mappend` (DiffList g) = DiffList (f.g)


-- A function that is used to create a writer with "dummy" values so a simple text
-- will be writter to the log.
tell :: w -> Writer w ()
Expand All @@ -42,3 +41,8 @@ toDiffList xs = DiffList (xs ++)
-- A function that is used to get a standard list from a given diffrent list.
fromDiffList :: DiffList a -> [a]
fromDiffList (DiffList f) = f []

-- Adds indentation to the Show instance of the given object
-- useful to make the logs prettier
showIndent :: (Show a) => a -> String
showIndent obj = "\t" ++ replace "\n" "\n\t" (show obj)
Empty file removed toPrint
Empty file.

0 comments on commit 7a1fc48

Please sign in to comment.