如何从Maybe中提取IO()并执行此操作?(How can I extract an IO () from Maybe and execute this?)
我有这个代码:
trick = Just (putStrLn "Hello?")
我想将这个
IO ()
从Maybe上下文解包并调用它。main = do foo <- trick foo
但是,这会引发错误:
Couldn't match type ‘IO’ with ‘Maybe’ Expected type: Maybe () Actual type: IO ()
我怎么解决这个问题?
I have this code:
trick = Just (putStrLn "Hello?")
And I want to unwrap this
IO ()
out the Maybe context and call it.main = do foo <- trick foo
However, this throws an error:
Couldn't match type ‘IO’ with ‘Maybe’ Expected type: Maybe () Actual type: IO ()
How could I resolve this?
原文:https://stackoverflow.com/questions/29516861
最满意答案
如果您阅读了count函数的文档 ,您将在本节中找到有关返回值的信息:
返回值
返回array_or_countable中的元素数。 如果参数不是数组或不是具有已实现Countable接口的对象, 则将返回1 。 有一个例外,如果array_or_countable为NULL,则返回0。
If you read the documentation of the count function, you'll find this section about the return value:
Return Values
Returns the number of elements in array_or_countable. If the parameter is not an array or not an object with implemented Countable interface, 1 will be returned. There is one exception, if array_or_countable is NULL, 0 will be returned.
相关问答
更多-
如何使用stdClass()将数组转换为对象(How to convert an array into an object using stdClass() [duplicate])[2021-04-08]
你只需要添加这个代码 $clasa = (object) array( 'e1' => array('nume' => 'Nitu', 'prenume' => 'Andrei', 'sex' => 'm', 'varsta' => 23), 'e2' => array('nume' => 'Nae', 'prenume' => 'Ionel', 'sex' => 'm', 'varsta' => 27), 'e3' => array( ... -
PHP:计数一个stdClass对象(PHP: Count a stdClass object)[2023-07-27]
问题是count是用来计算数组中的索引,而不是对象上的属性(除非它是实现Countable接口的自定义对象)。 尝试将对象,如下所示,作为数组,看看是否有帮助。 $total = count((array)$obj); 简单地将对象转换为数组不会总是工作,而是一个简单的stdClass对象,它应该在这里完成工作。 The problem is that count is intended to count the indexes in an array, not the properties on an ... -
在Python中解码StdClass(Decoding StdClass in Python)[2023-12-20]
基于此 ,你将不得不用pip或某些东西安装,我猜这是你想要的: from phpserialize import loads, phpobject python_object = loads(php_serialized_string, object_hook=phpobject) Based on this, which you'll have to install with pip or somesuch, I'm guessing this is what you want: from phpse ... -
如果您阅读了count函数的文档 ,您将在本节中找到有关返回值的信息: 返回值 返回array_or_countable中的元素数。 如果参数不是数组或不是具有已实现Countable接口的对象, 则将返回1 。 有一个例外,如果array_or_countable为NULL,则返回0。 If you read the documentation of the count function, you'll find this section about the return value: Return Va ...
-
在你看来: foreach($query as $row) { if(trim($row->player_item) != '') { echo $row->player_item . ' : ' . $row->total . '
'; } } In your view: foreach($query as $row) { if(trim($row->player_item) != '') { echo $row->player_item . ' : ' . $row ... -
如何从stdClass对象中的数组键获取值[复制](How to get a value from an array key within an stdClass Object [duplicate])[2023-02-08]
你迭代一个对象,而不是一个数组。 试试这种方式: foreach ($array->users as $obj) { echo $obj->id; } You iterate an object, not an array. Try this way: foreach ($array->users as $obj) { echo $obj->id; } -
在key [duplicate]中使用句点访问stdClass中的变量(Accessing variables in stdClass with period in key [duplicate])[2023-10-11]
将属性名称括在胡须和引号中: echo $object->{'Subscriber.AddResult'}; Enclose the property name in mustaches and quotes: echo $object->{'Subscriber.AddResult'}; -
$followers = $connection->get('users/show', array('screen_name' => $username)); $f = $followers->followers_count; 您正尝试将$ followers作为有时返回JSON的stdClass访问。 而是尝试以数组形式访问它$f = $followers['followers_count']; $followers = $connection->get('users/show', array('scr ...
-
PHP stdClass对象,如何获取0索引的元素[重复](PHP stdClass Object, how to get element with the 0 index [duplicate])[2022-01-26]
尝试这个: $obj = new stdClass(); $obj->{0} = 1; echo $obj->{0}; 来源: http : //php.net/manual/en/language.types.object.php Try this: $obj = new stdClass(); $obj->{0} = 1; echo $obj->{0}; source: http://php.net/manual/en/language.types.object.php -
您可以尝试使用大括号: $object->GetPlayerResult->{"RegistrationResponses.Player"} 或者您可以将其强制转换为关联数组 $result = (array) $object->GetPlayerResult; $player = $result["RegistrationResponses.Player"]; 如果使用json_decode解析网站响应,请注意第二个参数的存在是作为关联数组返回的: ASSOC 如果为TRUE,则返回的对象将转换为关联 ...