Skip to content

Instantly share code, notes, and snippets.

@Raynes
Created November 15, 2009 21:46
Show Gist options
  • Save Raynes/235496 to your computer and use it in GitHub Desktop.
Save Raynes/235496 to your computer and use it in GitHub Desktop.
module Main where
import Control.Monad
import Data.List
import Data.Char
import System.IO
import Text.Regex.Posix
import Text.Regex
getSecondWord :: String -> String
getSecondWord = head . tail . words
getLastWord :: String -> String
getLastWord = last . words
myReverse :: [b] -> [b]
myReverse = foldl (flip (:)) []
lastButOne :: [a] -> a
lastButOne = head . reverse . init
data Meow a = Meow a
deriving (Show)
splitDigits :: String -> [Int]
splitDigits = map digitToInt
addNum :: Int -> Int
addNum = foldl' (+) 0 . splitDigits . show
myLast :: [a] -> a
myLast = head . reverse
data Tree a = Node a (Tree a) (Tree a)
| Empty
deriving (Show)
countLetters :: String -> Int
countLetters xs =
length $ filter (/= ' ') $ subRegex (mkRegex "[^aA-zZ]") xs ""
data List a = Cons a (List a)
| Nil
deriving (Show)
fromList :: [a] -> List a
fromList (x:xs) = Cons x $ fromList xs
fromList [] = Nil
toList :: List a -> [a]
toList (Cons x xs) = x : (toList xs)
toList Nil = []
data Treetwo a = Nodetwo a (Maybe (Treetwo a)) (Maybe (Treetwo a))
deriving (Show)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment