Haskell DList

Append operation in haskell might be costlier ,if done this way

let x = “hello” ++ ” haskell”
let y = x ++ ” well done ”

to append this way have to traverse whole list each time ,a better alternative is :

(str1 ++) .(str2 ++ ).(str 3 ++) ……….

to do so in practice :

data DL a = DL {unwrap :: [a]->[a]}

createDL = DL ( [] ++ )

toList (DL f ) = f []

toDList :: DL a -> [a]-> DL a
toDList (DL f) a =DL $ f . (a ++)

instance Functor DL where
fmap f xs = DL (fmap f (toList xs) ++ )

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s