Skip to content

Instantly share code, notes, and snippets.

@HaiTo
Created August 23, 2017 11:07
Show Gist options
  • Save HaiTo/881f1140d1e197ac01965817a9fe6b5d to your computer and use it in GitHub Desktop.
Save HaiTo/881f1140d1e197ac01965817a9fe6b5d to your computer and use it in GitHub Desktop.
5_xx.hs
data Queue a = DeQue [a] [a] deriving (Show)
head' :: Queue a -> a
head' (DeQue (x:_) _) = x
checkf :: [a] -> [a] -> Queue a
checkf [] r = DeQue (reverse r) []
checkf l r = DeQue l r
tail' :: Queue a -> Queue a
tail' (DeQue (_:ls) r) = checkf ls r
snoc' :: Queue a -> a -> Queue a
snoc' (DeQue l r) x = checkf l (x : r)
-- balanceみたいなのを書く
main :: IO()
main = do
let q = DeQue [1, 2, 3] [6, 5, 4]
print q
print "---------"
print (head' q)
print "---------"
print (tail' q)
print "---------"
print (snoc' q 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment