Skip to content

Instantly share code, notes, and snippets.

@hakunin
Created March 2, 2010 15:50
Show Gist options
  • Save hakunin/319590 to your computer and use it in GitHub Desktop.
Save hakunin/319590 to your computer and use it in GitHub Desktop.
module Deque (Deque (First, Bottom), addFirst, addLast) where
import Prelude hiding (print)
data Deque a = First a (Deque a)
| Bottom
print :: (Show a)=> Deque a -> String
print Bottom = "Prazdny"
print (First f Bottom) = (show f)
print (First f d) = (show f) ++ "<=>" ++ print d
print Bottom = "Prazdny"
instance (Show a)=> Show (Deque a) where
show d = print d
addFirst :: a -> Deque a -> Deque a
addFirst x s = First x s
addLast :: a -> Deque a -> Deque a
addLast x (First e f) = First e (addLast x f)
addLast x (Bottom) = (First x Bottom)
module Stack (Stack (Element, Bottom), push, pop, top, isEmpty) where
import Prelude
data Stack a = Element a (Stack a)
| Bottom
push :: a -> Stack a -> Stack a
push x s = Element x s
pop :: Stack a -> Stack a
pop (Bottom) = error "Stack underrun"
pop (Element x s) = s
instance (Show a)=> Show (Stack a) where
show (Bottom) = "Prazdny"
show (Element e (Bottom)) = show e
show (Element e x) = show e ++ "->" ++ (show x)
top :: Stack a -> a
top (Bottom) = error "aaa"
top (Element x s) = x
isEmpty :: Stack a ->Bool
isEmpty (Bottom) = True
isEmpty (x) = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment