正如this question的回答中所述,%hide
directive允许人们无法访问现有名称:
import Data.String
%hide fib
%default total
fib : Nat -> Nat
fib n = loop n 0 1
where
loop : Nat -> Nat -> Nat -> Nat
loop Z a _ = a
loop (S k) a b = loop k b (a + b)
parseNat : String -> Maybe Nat
parseNat = map cast . parsePositive
response : String -> String
response s = case parseNat s of
Just n => "fib n = " ++ show (fib n)
Nothing => "n ∉ ℕ"
partial main : IO ()
main = repl "n = " ((++ "\n") . response)
这在上面的代码中工作正常:
*Main> :exec
n = 10
fib n = 55
然而,它似乎没有延续到REPL:
*Main> fib 10
Can't disambiguate name: Main.fib, Prelude.Nat.fib
如何让我的代码中的%hide
指令继续进入REPL?
答案 0 :(得分:2)
我认为您无法调用您的函数的唯一方法是使用其完全限定名称,例如Main.fib 10
可行。