This article by Chris Penner谈到了“无线光学”;即可以用来从结构中过滤出项目的光学。 本文使用以下"Van Laarhoven“表示法来表示这些光学元件: type Wither s t a b = forall f. Alternative f => (a -> f b) -> s -> f t 大多数(如果不是所有的) Van Laarhoven光学都有一个等效的profunctor表示。例如镜头: type Lens s t a b = forall f. Functor f => (a -> f b) ->
我有一个非常简单的用例,其中我有一个基本类型,但为了在我的数据模型中使用各种记录类型,我希望每个记录都有该类型的包装版本: type UID = Integer
-- specialised version
newtype MyRecordID = MyRecordID UID
-- constructor which can take any integral type because I get
-- Int32 from the database and it's a lot of annoying
-- boilerplate each time
myRecordID
当然,在Haskell中,类型构造函数可以接受类型参数。
当函数a -> b被视为“具有有趣构造函数名的类型”时,它的类型为(->) a b。这使得它成为一个带有两个参数的类型构造函数(->),a和b。在"reader“模式中经常遇到这种情况,就像在它的Functor和Applicative实例中一样:
instance Functor ((->) a) where
fmap = (.)
instance Applicative ((->) a) where
pure = const
(<*>) f g x = f x (g x
@Getter
@Setter
@Wither
class A {
protected final List<String> list;
//constructors
}
@Document
@Getter
@Setter
@Wither
class B extends A{
} 在这种情况下,类B被持久化,但当我试图从Mongo数据库读取文档时,我得到了以下异常:“没有访问者设置私有的最终A列表”如何解决这个问题?
我已经开始使用Lombok库了,我无法找出使用wither &一个构建器之间的区别。
@Builder
@Wither
public class Sample {
private int x;
private int y;
}
现在,我可以通过两种方式创建一个对象:
Sample s = new Sample().builder()
.x(10)
.y(15)
.build();
或
Sample s = new Sample()
.withx(10)
我有两个类型(<->)和(<-->)来表示类型之间的同构: data Iso (m :: k -> k -> *) a b = Iso { to :: m a b, from :: m b a }
type (<->) = Iso (->)
infix 0 <->
data (<-->) a b = Iso' { to' :: a -> b, from' :: b -> a }
infix 0 <--> 两者之间的唯一区别是,(<->)是一种更通用类型的
我有一个类,它包含了一个已经初始化的最终集。Mongo转换器看不到Set字段的访问器,@Wither也没有帮助,因为它不会生成方法(由于set正在初始化)。我能做什么? @Getter
@Setter
@Wither
@AllArgsConstructor
class A {
private final Set<String> setOfStrings = new HashSet<>();
} 收到的异常为 java.lang.UnsupportedOperationException: No accessor to set property final java
我用的是Lombok 1.18.8
compileOnly 'org.projectlombok:lombok:1.18.8'
这是我的简单课,上面写着@Wither:
@Wither
public class User {
private int a;
}
但是,当我试图在另一个类中调用withA()方法时,它不会出现:
class test {
User user = new User().withA(1); // withA is red
}
我的代码有什么问题?
UPD:其他Lombok注释工作。例如@Setter、Getter、@No
我看的是强的和封闭的profunctors类: 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) (
我有以下星座:
public final class ApplicationUser {
private final @Id
@Wither
long applicationUserId;
@NotNull
@Size(min = 4, max = 20)
private final
String login;
@NotNull
@Email
private final
String eMail;
@Wither
private Set<Privilege> privileges;
}
现在,我想通过ApplicationUser的login查询一个Query,这是由一个
更新:我在这里内联代码。
我正在尝试定义一个Data.Profunctor.Choice的实例,其中right是通过调用left来定义的,但是由于某种原因,编译器报告left是未知的。
newtype StateTrans s i o = ST (Tuple s i → Tuple s o)
instance stFunctor ∷ Functor (StateTrans s a) where
map f (ST st) = ST $ second f <<< st
instance stProfunctor ∷ Profunctor (StateTrans s) w
我有五六个资源,它们有很好的“with”处理程序,通常我会这样做:
with res1, res2, res3, res4, res5, res6:
do1
do2
但是,有时不应该激活这些资源中的一个或多个。这会导致非常丑陋的重复代码:
with res1, res3, res4, res6: # these always acquired
if res2_enabled:
with res2:
if res5_enabled:
with res5:
do1
我真的不想问这样的问题,但我在这里束手无策。我正在编写一个增量解析器,但由于某些原因,我不知道如何为它实现函式实例。下面是代码转储:
输入数据类型
输入是解析器向协同线生成的数据类型。它包含当前由coroutine和行结束条件操作的输入字符列表。
data Input a = S [a] Bool deriving (Show)
instance Functor Input where
fmap g (S as x) = S (g <$> as) x
输出数据类型
输出是coroutine向Parser生成的数据类型。它要么是失败的消息,完成b,或部分消息( ->输
实际上,我正在使用Parsec来表达Parser,我有一个小问题(我的法语也对不起我的英语)。
我有这样的代码:
data Expression ... -- Recursive type Expression
type Store [(String, Float)] -- variable's storage
type Parser a = Parsec String () a
parseExpr :: [Char] -> Either ParseError Expression
parseExpr string = parse expr "" stream
我喜欢镜头包里的。
mapped :: Prelude.Functor f => Setter (f a) (f b) a b
然而,我最近开始使用category包中的 (从这里开始,我将category的Functor称为Functor,否则使用Prelude.Functor ),因此我的mapped不再工作。
所以我想做一个可以和Functor一起工作的mapped版本。对于所有需要它的人来说,Functor的友好签名如下所示:
class (Category s, Category t) => Functor (s :: α -> α -> *) (t ::
我对Arrow进行了一段时间的学习和搜索,我对Arrow类的必要性感到有点困惑。如我所知,Arrow类是函数的抽象,Arrow A a b c表示的是b类型的输入和c类型的输出,它还提供了一些基本操作,如>>>、arr和first。
但是,我找不到b -> c类型的标准函数和A a b c类型的Arrow之间的任何区别。在我看来,first和>>>可以被\(b, c) -> (f b, c)和(.)取代。而且,由于箭头内部的每一个计算都是用函数表示的,如果我们用这些函数替换箭头,我认为没有什么不同。
总之,我认为Arrow计算图的每个节点(类似于
我是cmake和gcc的新手。我在公司的新角色的第一个任务是清除linux编译中的错误,我完成了大部分工作,现在我看到的唯一警告是
cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C [enabled by default]
我希望wither在cmake文件中抑制警告或解决问题。不幸的是,我仍然没有找到适合这里的正确的-Wno-xxx语句。
谢谢!
当人们输入我的URL时,我希望他们点击北卡罗来纳州或弗吉尼亚州。他们点击后,它会将他们重定向到www.myurl.com/nc或www.myurl.com/va。在他们回答了这个问题后,下次他们访问我的网站时,它会将他们重定向到相应的页面,而不会再次单击NC或VA。这是我到目前为止所得到的。我觉得我已经很接近了,但我真的不知道我在做什么。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transi