Created
February 9, 2022 03:53
-
-
Save altbodhi/de87b185f19ea895753c40208a8d607b to your computer and use it in GitHub Desktop.
Модульный подход к разработке на примере программы на языке F#
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
Форматируем исходники: fantomas . | |
Запускаем REPL с указанием дополнительный путей поиска исходников: dotnet fsi --lib:c:\lab\fscripts\MeteoInfo | |
В репле грузим основной модуль:> #load "Main.fsx";; | |
Загружаем ифну:> Main.printBarnaul();; | |
или запускаем скрипт из командной строки: dotnet fsi --exec main.fsx | |
или делаем файл исполняемым(в GNU Linux): | |
chmod +x Main.fsx | |
добавляем первой строкой | |
#!/usr/bin/env -S dotnet fsi --exec | |
и запускаем как обычную программу: ./Main.fsx | |
https://docs.microsoft.com/ru-ru/dotnet/fsharp/tools/fsharp-interactive/ | |
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
let color col = | |
let old = System.Console.ForegroundColor | |
System.Console.ForegroundColor <- col | |
{ new System.IDisposable with | |
member it.Dispose() = System.Console.ForegroundColor <- old } | |
let red () = color System.ConsoleColor.Red | |
let cyan () = color System.ConsoleColor.Cyan | |
let green () = color System.ConsoleColor.Green | |
let yellow () = color System.ConsoleColor.Yellow | |
let cls () = System.Console.Clear() |
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
#!/usr/bin/env -S dotnet fsi --exec | |
#load "Meteo.fsx" | |
open Meteo | |
let printBarnaul () = | |
MeteoInfo.Load "https://meteoinfo.ru/rss/forecasts/index.php?s=29838" | |
|> printMeteoInfo | |
#time | |
printBarnaul () |
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
#r "nuget: fsharp.data" | |
#load "ConsoleUtils.fsx" | |
#load "TextUtils.fsx" | |
open FSharp.Data | |
open ConsoleUtils | |
open TextUtils | |
type MeteoInfo = XmlProvider<"https://meteoinfo.ru/rss/forecasts/index.php?s=29838"> | |
let printMeteoInfo (data: MeteoInfo.Rss) = | |
cls () | |
for e in data.Channel.Items do | |
use _ = red () | |
printfn $"\n{e.Title}" | |
use _ = yellow () | |
e.Description |> fmt |> (printfn "%s") | |
use _ = cyan () in | |
printf $"\nОбновлено: " | |
use _ = green () in printfn $"{System.DateTime.Now:s}" |
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
let fmt s = | |
[| for c in s do | |
if System.Char.IsUpper c then yield '\n' | |
yield c |] | |
|> System.String |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment