Created
November 2, 2011 12:14
-
-
Save benkolera/1333486 to your computer and use it in GitHub Desktop.
Runtime Dependency Resolution ( by a haskell noob )
This file contains 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
import qualified Data.Map as Map | |
import Data.List | |
import Control.Applicative | |
englishTranslator = ("ENGLISH: " ++) | |
germanTranslator = ("GERMAN: " ++) | |
windowsUnlines = intercalate "\r\n" | |
unixUnlines = intercalate "\n" | |
translators = Map.fromList [ | |
("english",englishTranslator), | |
("german",germanTranslator) | |
] | |
unliners = Map.fromList [ | |
("windows",windowsUnlines), | |
("unix",unixUnlines) | |
] | |
processString :: ([String] -> String) -> ( String -> String ) -> [String] -> String | |
processString unliner translator = translator . unliner | |
makeStringProcessor osType language = | |
let | |
unliner = Map.lookup osType unliners | |
translator = Map.lookup language translators | |
in | |
case processString <$> unliner <*> translator of | |
Nothing -> error $ intercalate "" [ | |
"Cannot construct processor for os '", | |
osType, | |
"' and language '", | |
language, | |
"'" | |
] | |
Just f -> f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment