Last active
September 27, 2019 17:19
-
-
Save stacycurl/37a3b423d07d1faa382c78a3e8d349df to your computer and use it in GitHub Desktop.
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
sendText : HostName -> .base.Nat -> .base.Text ->{IO} () | |
sendText hostName port text = | |
serviceName = ServiceName.ServiceName (.base.Nat.toText port) | |
socket = clientSocket hostName serviceName | |
send socket (.base.Text.asciiBytes text) | |
closeSocket socket | |
base.Text.asciiBytes : .base.Text -> .base.Bytes | |
base.Text.asciiBytes = .base.Bytes.fromList . base.Text.asciiNats | |
base.Text.asciiNats : .base.Text -> [.base.Nat] | |
base.Text.asciiNats text = | |
asciiNat : .base.Text -> .base.Nat | |
asciiNat char = | |
case .base.Map.lookup char base.Text.asciiMap of | |
.base.Optional.Some nat -> nat | |
_ -> 32 | |
chars = base.Text.characters text | |
.base.List.map asciiNat chars | |
base.Text.asciiMap : .base.Map .base.Text .base.Nat | |
base.Text.asciiMap = | |
asciiCharacters = | |
base.Text.characters | |
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" | |
asciiRange = .base.List.range 32 127 | |
pairs = .base.List.zip asciiCharacters asciiRange | |
.base.Map.fromList pairs | |
base.Text.characters : .base.Text -> [.base.Text] | |
base.Text.characters text = base.List.unfold text base.Text.uncons | |
base.Text.uncons : .base.Text -> .base.Optional (.base.Text, .base.Text) | |
base.Text.uncons text = | |
case (take 1 text, drop 1 text) of | |
("", _) -> .base.Optional.None | |
(head, tail) -> .base.Optional.Some (head, tail) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment