gpt4 book ai didi

haskell - Haskell中函数的序列化

转载 作者:行者123 更新时间:2023-12-04 01:52:34 26 4
gpt4 key购买 nike

有没有办法在 Haskell 中序列化(读取/显示)函数?

例如,鉴于:

:t (+1) 
(+1) :: Num a => a -> a

我希望能够拥有类似的东西:
read "(+1)" :: Num a => a -> a

不幸的是,这会引发错误:
Could not deduce (Read (a -> a)) arising from a use of `read'
from the context (Num a)
bound by an expression type signature: Num a => a -> a
at <interactive>:1:1-30
Possible fix:
add (Read (a -> a)) to the context of
an expression type signature: Num a => a -> a
or add an instance declaration for (Read (a -> a))
In the expression: read "(+1)" :: Num a => a -> a
In an equation for `it': it = read "(+1)" :: Num a => a -> a

最佳答案

(通常)不可能显示一个函数,但是如果您在运行时有可用的 Haskell 编译器,则原则上可以读取一个函数。

关于haskell - Haskell中函数的序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6926151/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com