我当时正在研究强壮的和封闭的专业人士:
class Profunctor p where
dimap :: (a' -> a) -> (b -> b') -> p a b -> p a' b'
class Profunctor p => Strong p where
strong :: p a b -> p (c, a) (c, b)
class Profunctor p => Closed p where
closed :: p a b -> p (c -> a) (c -> b)
Run Code Online (Sandbox Code Playgroud)
((,)是对称bifunctor,因此它等效于“ profunctors”包中的定义。)
我注意到这两个(->) a和(,) a是endofunctors。似乎Strong并Closed具有类似的形式:
class (Functor f, Profunctor p) …Run Code Online (Sandbox Code Playgroud) 我们可以定义data Free f a = Pure a | Free (f (Free f a))等等Functor f => Monad (Free f).
如果我们定义
data T f a b = R a | S b | T (f a (T f a b))有一些我们类似M如此Profunctor f => M (T f a),在那里class Profunctor f where dimap :: (a -> b) -> (c -> d) -> f b c -> f a d?
自从我注意到以来,我一直在想,Data.Comp.Term.Context并且Free对于潜在的类比而言是同构的 …
我可以很容易地在Haskell中定义一般Functor和Monad类:
class (Category s, Category t) => Functor s t f where
map :: s a b -> t (f a) (f b)
class Functor s s m => Monad s m where
pure :: s a (m a)
join :: s (m (m a)) (m a)
join = bind id
bind :: s a (m b) -> s (m a) (m b)
bind f = join . map f
Run Code Online (Sandbox Code Playgroud)
我正在阅读这篇文章,它解释了一个应用函子是一个松散(封闭或幺半)的仿函数.它是在(指数或幺半群)bifunctor方面这样做的.我知道在Haskell类别中,每一个Monad都是Applicative …
问题是这个.我有:
f :: MonadIO m => ReaderT FooBar m Answer;
f = (liftIO getArgs) >>= ...
Run Code Online (Sandbox Code Playgroud)
我需要使用修改后的参数来运行它.但是,由于m是未知的,我不能简单地使用
mapReaderT (withArgs args) :: ReaderT r IO b -> ReaderT r IO b
Run Code Online (Sandbox Code Playgroud)
因为我需要以某种方式将所有m转换(withArgs args)为m.
我发现的一种可能性是定义我自己的withArgs,因此:
import System.Environment (setArgs, freeArgv);
withArgv new_args act = do {
pName <- liftIO System.Environment.getProgName;
existing_args <- liftIO System.Environment.getArgs;
bracket (liftIO $ setArgs new_args)
(\argv -> do {
_ <- liftIO $ setArgs (pName:existing_args);
liftIO $ freeArgv argv;
})
(const act);
};
withArgs xs act = do { …Run Code Online (Sandbox Code Playgroud) 在 Haskell 中,我可以定义一个内函子固定点,因此:
data Fix f = Fix (f (Fix f))
Run Code Online (Sandbox Code Playgroud)
但在 Agda 中不能:
data Fix (F : Id (Set ? Set)) : Set where
fix : (unId F) (Fix F) ? Fix F
Run Code Online (Sandbox Code Playgroud)
正如它所说的“Fix 不是严格的正数,因为它出现在 Fix 定义中构造函数 fix 类型中绑定变量的参数中。”
我尝试Coinduction.?从 stdlib 中使用,但徒劳无功:
data Fix (F : Set ? Set) : Set where
fix : ? (F (Fix F)) ? Fix F
Run Code Online (Sandbox Code Playgroud)
或者
data Fix (F : Set ? Set) : Set where
fix : F (? (Fix …Run Code Online (Sandbox Code Playgroud) 如何在 Agda 中制定依赖类型逻辑,而不是通过重用 Agda 类型系统本身来“作弊”?
\n\n我可以很容易地定义一个独立类型的逻辑:
\n\ninfixr 5 _\xe2\x87\x92_\ndata Type : Set where\n _\xe2\x87\x92_ : Type \xe2\x86\x92 Type \xe2\x86\x92 Type\n\ninfix 4 _\xe2\x8a\xa2_\ndata _\xe2\x8a\xa2_ : List Type \xe2\x86\x92 Type \xe2\x86\x92 Set where\n var : {a : Type} \xe2\x86\x92 [ a ] \xe2\x8a\xa2 a\n \xce\xbb\' : {a b : Type} {\xce\xb3 : _} \xe2\x86\x92 a \xe2\x88\xb7 \xce\xb3 \xe2\x8a\xa2 b \xe2\x86\x92 \xce\xb3 \xe2\x8a\xa2 a \xe2\x87\x92 b\n ply : {a b : Type} {\xce\xb3 \xce\xb4 : _} \xe2\x86\x92 \xce\xb3 \xe2\x8a\xa2 a \xe2\x87\x92 …Run Code Online (Sandbox Code Playgroud) 我正在修改一些代码以依赖于 rand 0.5 版。起初,我担心如何使用 生成我自己类型的随机值Standard,但我发现这是合法的:
impl ::rand::distributions::Distribution<MyType> for ::rand::distributions::Standard {
// ...
}
Run Code Online (Sandbox Code Playgroud)
为什么是合法的?我认为为外部类型实现外部特征是非法的。
例如见Data.Maybe.Base在STDLIB -所有的Maybe,Any和All有一个just构造函数.
Agda允许这些定义.如何指定使用哪一个?
haskell ×4
agda ×3
functor ×3
profunctor ×2
applicative ×1
categories ×1
free-monad ×1
logic ×1
monads ×1
orphan ×1
rust ×1
traits ×1
type-theory ×1