CIS194/Lecture 02/Scrabble/Scrabble.hs

23 lines
543 B
Haskell
Raw Normal View History

module Scrabble where
import Words
import Data.List
type Hand = [Char]
formableBy :: String -> Hand -> Bool
formableBy [] _ = True
formableBy (x:xs) hand = let remainingHand = delete x hand in
elem x hand && formableBy xs remainingHand
wordsFrom :: Hand -> [String]
wordsFrom hand = wordsFromList hand allWords
wordsFromList :: Hand -> [String] -> [String]
wordsFromList hand [] = []
wordsFromList hand (x:[])
| formableBy x hand = [x]
| otherwise = []
wordsFromList hand (x:xs) = wordsFromList hand [x] ++ wordsFromList hand xs