请看代码。我相信使用幻像类型使得模式匹配无可辩驳,因此实例中不需要MonadFail。
{-# LANGUAGE DataKinds #-}\n{-# LANGUAGE GADTs #-}\n\n{-# OPTIONS_GHC -Wall #-}\n{-# OPTIONS_GHC -Wincomplete-uni-patterns #-}\n\ndata Type = I | S\n\ndata T t where\n TI :: Int -> T 'I\n TS :: String -> T 'S\n\nti :: T 'I\nti = TI 42\n\ntest :: Monad m => m Int \ntest = do\n (TI v) <- return ti\n return v\nRun Code Online (Sandbox Code Playgroud)\n但我收到此错误:
\n \xe2\x80\xa2 Could not deduce (MonadFail m)\n arising from a do statement\n with the failable pattern \xe2\x80\x98(TI v)\xe2\x80\x99\nRun Code Online (Sandbox Code Playgroud)\n … 我试图在Haskell中试验System-F类型,并通过实现自然数的Church编码type.
加载此代码时
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE RankNTypes #-}
type CNat = forall t . (t -> t) -> (t -> t)
c0 :: CNat
c0 _ x = x
type CPair a b = forall t . (a -> b -> t) -> t
cpair :: a -> b -> CPair a b
cpair a b f = f a b
-- pair3 :: CPair CNat String
pair3 = cpair c0 "hello"
Run Code Online (Sandbox Code Playgroud)
进入ghci 7.8.2我收到警告:
?: :l …Run Code Online (Sandbox Code Playgroud) 我想通过一个测试语法异常的宏来扩展srfi-78.我想要这样的东西:
#! /usr/bin/env scheme-script
#!r6rs
(import (rnrs) (srfi :78 lightweight-testing))
; the macros I want to test
(define-syntax some-macros
(syntax-rules ()
[(_) 'ok]))
; the extension to srfi-78
(define-syntax check-exception
(syntax-rules ()
; ... some code ...
))
; tests
; prints "correct" or someting like that
(check (some-macros) => 'ok)
; should print "correct" (i. e. the test passed)
(check-exception (some-macros 'arg))
; should print "error"
; (i. e. the exception was not thrown as expected)
(check-exception (some-macros))
Run Code Online (Sandbox Code Playgroud)
有可能吗?如果没有,你会如何编写宏的测试? …
是否可以在 buildroot 的外部树(由 BR2_EXTERNAL 变量指定的树)中拥有一个主机包?我知道我可以实现这样的包,如果存在任何依赖它的包,它将被构建。但是如果没有板包依赖它呢?例如,当我们需要为支持的电路板构建模拟器时可能就是这种情况。换句话说,我需要外部目录中的 Config.in.host 之类的东西。