Upgrade to Pro — share decks privately, control downloads, hide ads and more …

F#で自在につくる静的ブログサイト - 関数型まつり2025

F#で自在につくる静的ブログサイト - 関数型まつり2025

関数型まつり2025 での登壇資料です。

Avatar for pizzacat83

pizzacat83

June 13, 2025
Tweet

More Decks by pizzacat83

Other Decks in Programming

Transcript

  1. Fornax のしくみ loaders/*.fsx fun (sc: SiteContents) ... : SiteContents =

    ... sc.Add(post) sc generators/*.fsx fun (sc: SiteContents) ... : {path,data}[] = let posts = sc.GetValues<Post> () posts |> Seq.map ... sc: SiteContents
  2. F# でスクリプトを呼び出してみる let runScript (path: string) (input: string): string =

    // ... use fsi = FsiEvaluationSession.Create(fsiConfig, a fsi.EvalInteraction $"#load \"{path}\";;" let funcResult: FsiValue option = fsi.EvalExpressi let funcObj: obj = match funcResult with | Some funcValue -> funcValue.ReflectionValue | _ -> failwith "error" let resultObj: obj = funcObj.GetType().GetMethod(" match resultObj with | :? string as s -> s | _ -> failwith "error" 1 2 3 // script.fsx ( : ): let "hello, {s}!" s string string $ calc = (1) Init FSI (2) Load script (3) Grab the function (4) Invoke the function
  3. F# でスクリプトを呼び出してみる use fsi =
 FsiEvaluationSession.Create (fsiConfig, argv, inStream, outStream,

    errStream) (1) Init FSI (2) Load script (3) Grab the function (4) Invoke the function
  4. F# でスクリプトを呼び出してみる fsi.EvalInteraction $"#load \"{path}\";;" (1) Init FSI (3) Grab

    the function (4) Invoke the function (2) Load script REPL の #load “script.fsx”;; と同等
  5. F# でスクリプトを呼び出してみる let funcResult: FsiValue option = fsi.EvalExpression $"{moduleName path}.calc"

    let funcObj: obj = match funcResult with | Some v -> v.ReflectionValue | _ -> failwith "error" (1) Init FSI (2) Load script (4) Invoke the function (3) Grab the function FSI で “Script.calc” を評価した結果を取り出す
  6. F# でスクリプトを呼び出してみる let resultObj: obj = funcObj.GetType().GetMethod("Invoke") .Invoke(funcObj, [| input

    |]) match resultObj with | :? string as s -> s | _ -> failwith "error (1) Init FSI (2) Load script (3) Grab the function (4) Invoke the function input を引数として funcObj を呼び出す