在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?

请每个回答只回答一个特征。


当前回答

Haskell's use of Maybe and Just. Maybe a is a type constructor that returns a type of Just a, but Maybe Int won't accept just an Int, it requires it to be a Just Int or Nothing. So in essence in haskell parlance Just Int is about as much of an Int as an apple is an orange. The only connection is that Just 5 returns a type of Maybe Interger, which can be constructed with the function Just and an Integer argument. This makes sense but is about as hard to explain as it can theoretically be, which is the purpose of haskell right? So is Just really JustKindaLikeButNotAtAll yea sorta, and is Maybe really a KindaLooksLikeOrIsNothing, yea sorta again.

-- Create a function that returns a Maybe Int, and return a 5, which know is definitly Int'able
>  let x :: Maybe Int; x = 5;
<interactive>:1:24:
    No instance for (Num (Maybe Int))
      arising from the literal `5' at <interactive>:1:24
    Possible fix: add an instance declaration for (Num (Maybe Int))
    In the expression: 5
    In the definition of `x': x = 5

>  Just 5  
Just 5
it :: Maybe Integer

    -- Create a function x which takes an Int
>  let x :: Int -> Int; x _ = 0;
x :: Int -> Int
-- Try to give it a Just Int
>  x $ Just 5                   

<interactive>:1:4:
    Couldn't match expected type `Int' against inferred type `Maybe t'
    In the second argument of `($)', namely `Just 5'
    In the expression: x $ Just 5
    In the definition of `it': it = x $ Just 5

祝你好运读到这篇文章,我希望它是正确的。

其他回答

在Python中,至少对我来说,这是非常wft的!我第一次看的时候:

>>> "ja " * 5
'ja ja ja ja ja '

你可以将字符串相乘!WTF ? ?

PS:我认为这是因为x * n意味着:n乘以x,所以,5次“ja”是“ja”“ja”“ja”“ja”“ja”“ja”,因为你可以像这样连接字符串:

>>> "ja ""ja ""ja ""ja ""ja "
'ja ja ja ja ja '

两个代码有相同的结果(可能是相同的)

在php中:

easter_date -获取给定年份复活节午夜的Unix时间戳

Int easter_date ([Int $year])

在MOD_REWRITE

RewriteRule ^([a-zA-Z0-9_-]+)\.php$ $1/ [R,NC]
RewriteRule ^([a-zA-Z0-9_-]+)/$ $1\.php [NC,L]

将会导致:

"file.php > file > file.php > file > file.php > file >  ..."

最后:

Error 500 Too Many Redirects

(一般来说,我发现编辑.htaccess文件和构造一个正常运行的正则表达式一样乏味。)

在ColdFusion

Struct(又名Java HashMap)是通过引用传递的。

你可能认为其他数据类型的行为就像Java…

数组是按值传递的,wtf!

List只是一个普通的逗号分隔的字符串!

Javascript中有很多东西会让你流泪。

局部变量的作用域,举个简单的例子:

function foo(obj)
{
  for (var n = 0; n < 10; n++)
  {
    var t;        // Here is a 't'
    ...
  }
  t = "okay";     // And here's the same 't'
}