我有以下代码
let f2 x:int =
fun s:string ->
match x with
| x when x > 0 -> printfn "%s" s
| _ -> printfn "%s" "Please give me a number that is greater than 0"
Run Code Online (Sandbox Code Playgroud)
编译器抱怨:
Unexpected symbol ':' in lambda expression. Expected '->' or other token.
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
当我在f#中查找seq类型时,最后一个参数总是像源一样
Seq.pick chooser source
Seq.concat sources
Run Code Online (Sandbox Code Playgroud)
为什么?那是因为讨好吗?
我有以下声明
iex(5)> a = <<3>>
<<3>>
iex(6)> b = <<a::binary>>
<<3>>
Run Code Online (Sandbox Code Playgroud)
第一行,我创建了一个值为 3 的二进制文件。在第三行,我希望 shell 向我显示 00000011 而不是 3。我知道首先创建一个二进制文件(1.line)然后再次转换为二进制文件是没有意义的。但我期待 shell 显示 00000011 而不是 3。
当二进制像浮动一样
iex(7)> a = << 5.3 :: float >>
<<64, 21, 51, 51, 51, 51, 51, 51>>
Run Code Online (Sandbox Code Playgroud)
我不明白,为什么它显示我这个数字?
我有以下界面:
public interface ISapFunction
{
void Import<T>(T obj);
T Export<T>();
void Call(RfcRepository repo, RfcDestination dest);
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试按如下方式实现它:
public class SapMaterialFormatter : ISapFunction
{
private static SapMaterialFormatter _self;
private string _formatted;
private string _raw;
private SapMaterialFormatter()
{
}
public void Import<string>(string obj)
{
_raw = obj;
}
public string Export<string>()
{
return _formatted;
}
public void Call(RfcRepository repo, RfcDestination dest)
{
var bapi = repo.CreateFunction("FUNCTION");
bapi.SetValue("IF_INPUT", _raw);
bapi.Invoke(dest);
_formatted = bapi.GetString("EF_OUTPUT");
}
public static SapMaterialFormatter Factory()
{
return _self ?? new …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习haskell并且无法配置它,为什么以下代码片段无法编译:
*Uncurry> applyTwice f x = f f x
<interactive>:14:20: error:
• Occurs check: cannot construct the infinite type:
t ~ t -> t2 -> t1
• In the first argument of ‘f’, namely ‘f’
In the expression: f f x
In an equation for ‘applyTwice’: applyTwice f x = f f x
• Relevant bindings include
x :: t2 (bound at <interactive>:14:14)
f :: t -> t2 -> t1 (bound at <interactive>:14:12)
applyTwice :: (t -> t2 -> t1) …Run Code Online (Sandbox Code Playgroud) Haskell中的所有功能都是:
Prelude> type Subject = String
Prelude> type Verb = String
Prelude> type Object = String
Prelude> data Sentence = Sentence Subject Verb Object deriving (Eq, Show)
Prelude> :t Sentence
Sentence :: Subject -> Verb -> Object -> Sentence
Run Code Online (Sandbox Code Playgroud)
Sentence是一个数据类型,但为什么它显示为一个函数?即使我用一个值替换,它感觉就像一个函数.
s1 = Sentence "dogs" "drool"
Run Code Online (Sandbox Code Playgroud)
数据类型是否也支持currying?
我做了一个错误包并写了这样一个函数:
Prelude> doWork f x = f f x
Run Code Online (Sandbox Code Playgroud)
我有一个编译器错误:
<interactive>:3:16: error:
• Occurs check: cannot construct the infinite type:
t ~ t -> t1 -> t2
• In the first argument of ‘f’, namely ‘f’
In the expression: f f x
In an equation for ‘doWork’: doWork f x = f f x
• Relevant bindings include
x :: t1 (bound at <interactive>:3:10)
f :: t -> t1 -> t2 (bound at <interactive>:3:8)
doWork :: (t -> t1 -> …Run Code Online (Sandbox Code Playgroud) 我有以下表达式:
1 + "c"
Run Code Online (Sandbox Code Playgroud)
结果我得到了
1c
Run Code Online (Sandbox Code Playgroud)
我想,因为编译器将表达式转换为:
1.toString + "c"
Run Code Online (Sandbox Code Playgroud)
对我来说它根本不是逻辑,我期待一个异常,因为表达式的第一个参数是a Int,它决定了结果类型.
如果它会反过来像
"c" + 1
Run Code Online (Sandbox Code Playgroud)
然后我同意,该值应该是一个字符串.
为什么编译器不在第一个表达式上抛出异常?
我对弱头正常形态和正常形态有疑问.
弱头普通形式意味着,表达式只会在达到数据构造函数时进行评估.
正常形式表示,表达式将被完全评估.
现在,我有以下表达式:
\x -> x * 10
Run Code Online (Sandbox Code Playgroud)
为什么上面的表达式是正常的?
"Papu" ++ "chon"
Run Code Online (Sandbox Code Playgroud)
为什么上面的表达既不是WHNF也不是NF?
我有以下功能:
isElemChar :: Char -> Bool
isElemChar x = elem x ['A'..'Z'] || elem x ['a'..'z']
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下功能时:
isElemChar 5
Run Code Online (Sandbox Code Playgroud)
然后我有例外:
<interactive>:73:12: error:
* No instance for (Num Char) arising from the literal `5'
* In the first argument of `isElemChar', namely `5'
In the expression: isElemChar 5
In an equation for `it': it = isElemChar 5
*Cipher Data.Char> isElemChar 'a'
Run Code Online (Sandbox Code Playgroud)
如何使功能更安全?哪种方法可以使其达到全部功能?
我可以使用Maybe数据类型,但不知道如何实现它.