
Recent Posts
Recent Comments
Archives
Categories
Meta
Advertisements
data BT a = Leaf a Node (BT a) (BT a) Empty deriving (Show,Eq) — creating unbalanced tree from List mkTree (x:y:xs) = Node (Node (Leaf x ) (Leaf y ) ) (mkTree xs) mkTree [] = Empty mkTree [x] … Continue reading
Wrote one Java version on currency convertor https://ratndeo.wordpress.com/2012/10/23/javasubmissiontointerfaces/ Here comes sophisticated Haskell version : data Operation = Add  Sub Mul Div deriving (Show,Eq) data Unit = Unit  Dollar  INR  EURO deriving (Show,Eq) data UnitPair = UnitPair … Continue reading
A common currency operation and exchange taken from a book : a demonstration in dummy code (50$ + 100INR 30 EURO) convert to EURO Solution : Convert currency operation and exchange to one interface
Haskell does some nice work for us .It defines default equality for us based on value constructor,a simple illustration : data Color = Red GreenBlue deriving (Show) instance Eq Color where a == b = case (a ,b ) of … Continue reading
{# LANGUAGE MultiParamTypeClasses #} data Km =Km Double deriving (Show,Eq) data Mile = Mile Double deriving (Show,Eq) data MyMile = MyMile Double deriving (Show,Eq) class Converter a b where convert:: a>b instance Converter (Km ) (Mile ) where convert (Km … Continue reading
split _ [] = [[]] split a xs = let (ys,zs) = break (==a) xs in ys:case zs of [] >[] _> split a $ tail zs –sample run split ‘,’ “hello ryan, dont play too much,take some sleep” [“hello … Continue reading
Java folks must appreciate ,that Haskell does not have Null type For optional values it got elegant solution – Maybe a = Just a Nothing for example [Just 1,Just 2,Just 3,Nothing ] is a list of type Maybe Integer and … Continue reading