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

Fibonacci Butt Sort

Name: Anonymous 2009-08-16 23:08

Let us discuss the various implementations of theFIBONACCI BUTT SORT.

Name: Anonymous 2009-09-07 12:38

-- buttsort.hs - an implementation of the Fibonacci Buttsort
import Data.Char (isSpace)
import Control.Monad.State

data Tag = Tag String
           deriving (Show, Eq)

class Text a where
    value :: a -> String

instance Text Char where
    value = (:[])

instance (Text a) => Text [a] where
    value = concatMap value

(<<) :: (Text a) => Tag -> a -> String
infixr <<
(Tag t) << x = "[" ++ t ++ "]" ++ value x ++ "[/" ++ t ++ "]"

[b, i, o, u, m] = map Tag ["b", "i", "o", "u", "m"]

buttsortW, buttsortC :: String -> String
buttsortW = (b <<) . (i <<) . unwords . zipWith (<<) (cycle [u, o]) . words
buttsortC = (b <<) . (i <<) . concat . flip evalState (cycle [u, o]) . mapM f
  where f c = if isSpace c then return [c]
                else do t <- get
                        modify tail
                        return $ head t << c


EXPERT HASKELL PROGRAMMING

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