Skip to content

Instantly share code, notes, and snippets.

@altbodhi
Created February 9, 2022 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save altbodhi/de87b185f19ea895753c40208a8d607b to your computer and use it in GitHub Desktop.
Save altbodhi/de87b185f19ea895753c40208a8d607b to your computer and use it in GitHub Desktop.
Модульный подход к разработке на примере программы на языке F#
Форматируем исходники: 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/
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()
#!/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 ()
#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}"
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