aboutsummaryrefslogtreecommitdiff
path: root/examples/guess-number.ts
blob: aca39156881232ded0028001c2a2c6fa5e718bfb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { Print, PutString, Bind, Kind1, JsExpr, ReadLine, Seq } from '../src/stdlib'

export type main = Bind<
  JsExpr<"Math.floor(Math.random() * 10)">,
  StartGuessing
>

interface AskForGuess<N extends number> extends Kind1<string> {
  return: this['input'] extends `${N}` ? Print<"Yaya"> : Print<"naaah">
}

interface StartGuessing extends Kind1<number> {
  return: Bind<Seq<[PutString<"Your guess? ">, ReadLine]>, AskForGuess<this['input']>>
}