Created
November 15, 2009 21:46
-
-
Save Raynes/235496 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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