Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Useless Non-Programmers Who Love Programming

Name: Anonymous 2013-12-09 15:54

Has anyone from this board actually written anything of note
? I, for example, am the inventor of Haskell, and have been a longtime /prague/ lurker. What have you ever done?

Name: Anonymous 2013-12-11 4:56

From rosetta code:

data Fifo a = F [a] [a]
 
emptyFifo :: Fifo a
emptyFifo = F [] []
 
push :: Fifo a -> a -> Fifo a
push (F input output) item = F (item:input) output
 
pop :: Fifo a -> (Maybe a, Fifo a)
pop (F input (item:output)) = (Just item, F input output)
pop (F []    []           ) = (Nothing, F [] [])
pop (F input []           ) = pop (F [] (reverse input))
 
isEmpty :: Fifo a -> Bool
isEmpty (F [] []) = True
isEmpty _         = False

LOL reverse input. Amortized constant time LOL

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List