我正在尝试使用 Hint ( Language.Haskell.Interpreter )在运行时编译Polysemy monad 值 )。
当我尝试这样做时,我确实得到了一个关于:在“交互式”代码中不正确使用运算符的错误;似乎传递给 GHC 的文本提示存在语法错误。
{-# LANGUAGE DataKinds #-}
module Main where
import Polysemy (Embed, embed, runM, Sem)
import Language.Haskell.Interpreter (as, interpret, Interpreter, runInterpreter, setImportsQ)
import Data.Typeable (typeOf)
import Control.Monad.IO.Class (liftIO)
main :: IO ()
main = do
-- Hint works fine to interpret a String:
m <- interpretWithErrors exampleHint
print m
-- And Sem works fine:
runM exampleSem
-- But notice the weird detected type:
print $ typeOf exampleSem …Run Code Online (Sandbox Code Playgroud) 我正在尝试处理一个dict对象,PyCharm 给了我一个意外的类型警告。
这是一个产生警告的简化示例:
X = type("X", (), {})
def big_foo(data: Dict[str, Any]) -> Dict[str, Any]:
def little_foo(entries: Iterable[Tuple[str, Any]]) -> Iterable[Tuple[X, Any]]:
pass
def little_bar(entry: Tuple[X, Any]) -> Tuple[str, Any]:
pass
return dict(map(little_bar, little_foo(data.items())))
Run Code Online (Sandbox Code Playgroud)
PyCharm 将此警告附加到data.items()最后一行的短语中:
Expected type 'Iterable[Tuple[str, Any]]', got 'ItemsView[str, Any]' instead
Run Code Online (Sandbox Code Playgroud)
我曾自信地预期dict.items()会返回某种Iterable元组。有没有好的方法向 PyCharm 解释发生了什么?代码实际上有问题吗?
Base 提供ZipList,它只是[]where <*>is basedzip而不是笛卡尔积的包装器。这不是默认设置,因为它与Monad []实例不一致,但有些人发现它更直观,并且这两种行为在不同的上下文中都很有用。
Edward Kmett 提供Distributive,Traversable. 一个 Traversable 可以被映射/推送/分发到任何 Applicative Functor 中;可以从任何 Functor 中提取/分解一个 Distributive。(由于我没有拆包的原因,distribute不需要外层是适用的。)
长度索引列表是 Distributive,并且按您期望的方式工作。具体来说,他们的 Applicative 实例基于zip,就像ZipList! 这表明ZipList也可能是Distributive,这将是有用的。
文档的Distributive注意事项必须是任何实例的两件事:
(->) x对于某些人来说,它 [必须] 同构x。”
Int ->。ZipList。这够好吗?今天下午我花了几个小时试图写作instance Distributive ZipList where distributive = ...,但无法让它发挥作用。对于 …
我正在尝试更新使用Text.Parsec.Expr的秒差距解析器。我正在尝试(这可能是不明智的,但看起来应该是实用的)将 DSL 验证的一部分构建到解析器中。但我很难让它与类型一起工作,它的主体需要是一个生成函数的解析器buildExpressionParserOperator。
data Location = Location { owners :: PartySet, source :: SourcePos } deriving (Eq, Ord, Show)\ntype Located = (,) Location\ntype Parser = Parsec String (Map Variable PartySet)\n\n-- Pair a parsed thing with it\'s position in the source file\npositioned :: Parser a -> Parser (SourcePos, a)\npositioned p = do source <- getPosition\n (source,) <$> p\n\nchooseOf :: (TokenParser st -> t -> Parsec.Parser a) -> [t] -> Parser (SourcePos, a)\nchooseOf …Run Code Online (Sandbox Code Playgroud) haskell ×3
applicative ×1
distributive ×1
ghc ×1
hint ×1
parsec ×1
pycharm ×1
python ×1
python-3.7 ×1
python-3.x ×1
runtime ×1
traversable ×1
typing ×1