-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
120 additions
and
149 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,33 @@ | ||
module Course05 where | ||
|
||
import Control.Monad.IO.Class | ||
import Data.Char | ||
import Data.Word | ||
import Prelude hiding ((==), Bounded, Enum, Eq, Ordering, Show) | ||
|
||
mkEmailSafe :: String -> String -> String -> Either String String | ||
mkEmailSafe user host ext = | ||
checkUsername user | ||
>>= \(username :: String) -> | ||
checkExt ext | ||
>>= \(extension :: String) -> | ||
Right (username ++ "@" ++ host ++ "." ++ extension) | ||
|
||
checkUsername :: String -> Either String String | ||
checkUsername s | all isLower s = Right s | ||
| otherwise = Left ("Username should be lowercase, but found: " ++ s) | ||
checkExt :: String -> Either String String | ||
checkExt = | ||
\case | ||
"com" -> Right "com" | ||
"fr" -> Right "fr" | ||
s -> Left ("Unexpected extension: " | ||
++ show s | ||
++ ". Expected one of: [\"com\", \"fr\"]") | ||
|
||
mkEmailSafe' :: String -> String -> String -> Either String String | ||
mkEmailSafe' user host ext = do | ||
username <- checkUsername user | ||
extension <- checkExt ext | ||
pure (username ++ "@" ++ host ++ "." ++ extension) | ||
|
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Mastering the Type System</title> | ||
<meta charset="utf-8"> | ||
<style> | ||
@import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz); | ||
@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic); | ||
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic); | ||
|
||
body { font-family: 'Droid Serif'; } | ||
h1, h2, h3 { | ||
font-family: 'Yanone Kaffeesatz'; | ||
font-weight: normal; | ||
} | ||
.remark-code, .remark-inline-code { font-family: 'Ubuntu Mono'; } | ||
.remark-inline-code { background-color: #F0F0F0; } | ||
</style> | ||
</head> | ||
<body> | ||
<!-- See https://github.com/gnab/remark/wiki for guidance --> | ||
<script src="https://remarkjs.com/downloads/remark-latest.min.js"> | ||
</script> | ||
<script> | ||
var slideshow = remark.create({ | ||
sourceUrl: 'course-05.md' | ||
}); | ||
</script> | ||
</body> | ||
</html> | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ library slides | |
Course02 | ||
Course03 | ||
Course04 | ||
Course05 | ||
|
||
executable TP1.hs | ||
import: common-all | ||
|