LoginSignup
1
0

More than 5 years have passed since last update.

SATySFiでoptionalな型をつける方法

Posted at

?:でoptional引数として定義する

@require: stdja

let-inline ctx \sugoi ?:prefix s =
  let p = match prefix with
    | None -> `すごい`
    | Some(p) -> p
  in
  read-inline ctx (embed-string (p ^ s))
in

document (|
  author = { Seiei MIYAGI };
  show-title = true;
  show-toc = false;
  title = { SATySFiでoptional }
|) '<
 +p { \sugoi(`ねむい`); }
 +p { \sugoi?:(`やばい`)(`ねむい`); }
>

実行結果

Screenshot from 2018-10-18 11-34-26.png

matchNoneSomeにマッチさせる

sugoi.saty
@require: stdja

let-inline ctx \sugoi s =
  let s = match s with
    | None -> `すごい`
    | Some(s) -> s
  in
  read-inline ctx (embed-string s)
in

document (|
  author = { Seiei MIYAGI };
  show-title = true;
  show-toc = false;
  title = { SATySFiでoptional }
|) '<
 +p { \sugoi(None); }
 +p { \sugoi(Some(`すごくない`)); }
>

実行結果

Screenshot from 2018-10-18 10-56-21.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0