在我开始之前,我想为我的问题的相当普遍的类型道歉 - 我确信整本书可以写在那个特定主题上.
让我们假设您有一个包含多个文档模式的大型文档数据库,以及每个模式的数百万个文档.在应用程序的生命周期中,需要经常更改已存储文档的模式(和内容).
这样的改变可能是
我我在这里我们使用了SQL数据库,我们在导致一些显著的离线时间(24/7产品)时的变化成为了激烈的SQL数据块通常会做一个表上的LOCK发生更改时一些非常相似的challanges最后一个项目.我想避免这种情况.
另一个相关问题是如何在使用的编程语言环境中处理模式更改.通常通过更改类定义来发生模式更改(我将使用Mongoid为MongoDB和Ruby使用OR-Mapper).如何处理不符合我最新类定义的旧版本文档.
如何在嵌套目录树中定义子项目,其中子项目文件夹不是根项目的直接子项
root
lala
A
lulu
B
Run Code Online (Sandbox Code Playgroud)
现在我想添加A&B作为子项目.如果我做
//settings.gradle
include "lala:A", "lulu:B"
Run Code Online (Sandbox Code Playgroud)
然后还将"lala"和"lulu"添加为子项目.但是我只想添加A&B而不是其他任何东西.
我有以下简单的代码
import Data.String.Regex
import Data.Array
last <$> match someRegex " 1"
Run Code Online (Sandbox Code Playgroud)
哪里
match someRegex " 1"
Run Code Online (Sandbox Code Playgroud)
返回类似的东西
Just ([Just (" 1"),Just (" "),Just ("1")])
Run Code Online (Sandbox Code Playgroud)
和
last <$> match someRegex " 1"
Run Code Online (Sandbox Code Playgroud)
返回类似的东西
Just (Just (Just (" 1")))
Run Code Online (Sandbox Code Playgroud)
现在我有一个深深嵌套的Maybe.这使得它很难处理(甚至使用仿函数).我给自己写了一对辅助函数 - 但我对此并不满意.它不知何故感觉不对.
extract j = do
case j of
Nothing -> Nothing
Just a -> a
extract2 jj = extract $ extract jj
Run Code Online (Sandbox Code Playgroud)
然后像这样使用它
extract2 $ last <$> match someRegex " 1"
Run Code Online (Sandbox Code Playgroud)
在Purescript/Haskell中有没有更好/惯用的方法来做这些事情?
给出以下类型和成员函数
type Result<'TSuccess, 'TError> =
| Success of 'TSuccess
| Error of 'TError list
with
member this.apply fn =
match (fn, this) with
| Success(f), Success(x) -> Success(f x)
| Error(e), Success(_) -> Error(e)
| Success(_), Error(e) -> Error(e)
| Error(e1), Error(e2) -> Error(List.concat [e1;e2])
Run Code Online (Sandbox Code Playgroud)
以及内联函数
let inline (<*>) (f: ^A) (t:^A) =
let apply' = (^A : (member apply : ^A -> ^A) (t, f))
apply'
Run Code Online (Sandbox Code Playgroud)
而这个电话网站
let y () = Success (fun x -> x + 1) <*> …Run Code Online (Sandbox Code Playgroud) 尝试通过反射运行f#代码时,我有一些奇怪的效果.
给出以下类型
type Box<'a, 'b> = Box of 'a * 'b
Run Code Online (Sandbox Code Playgroud)
和这个功能
//iToS :: Box<'a,'b> -> Box<string,'b>
let iToS (Box (i, v)) = Box ((sprintf "%A" i), v)
Run Code Online (Sandbox Code Playgroud)
我可以轻松,正确地运行以下代码
let r01 = iToS (Box (1, 1))
Run Code Online (Sandbox Code Playgroud)
但是我需要在系统边界的尖锐边缘运行此功能,这样做的唯一方法是减少反射使用.
所以我创建了这个函数,它应该采用类似上面的函数和给定类型的记录并应用它.
let convert<'t> (f:Quotations.Expr) (v:'a) : 't =
let methi e =
let rec methi' e =
match e with
| Call (x, mi, y) -> mi
| Lambda (_, body) -> methi' body
| _ -> failwith <| sprintf "not a function …Run Code Online (Sandbox Code Playgroud) 是否有可能为记录创建一个fmap,以便我可以应用相同的功能来记录类似bur不同类型的字段
假设我有一个记录字段类型Item和记录X和功能transform
type Item<'a, 'b> = Item of 'a * 'b
let transform (i: Item<'a, 'b>) : Item<'a, string> =
let (Item (x, y)) = i
Item (x, sprintf "%A" y)
type X<'a> = {
y: Item<'a, int>
z: Item<'a, bool>
}
with
member inline this.fmap(f) =
{
y = f this.y
z = f this.z
}
Run Code Online (Sandbox Code Playgroud)
现在该行z = f this.z抱怨给定的类型应该是Item<'a, int>其类型Item<'a, bool>.显然,类型推断器
已经确定函数f是类型Item<'a, int> -> …
我如何覆盖Zero以下代码中的方法,以便我可以返回Euro(0)到中的定义type Euro
[<AbstractClass>]
type Currency () =
abstract member Zero<'T when 'T :> Currency > : unit -> 'T
type Euro (value: int) =
inherit Currency()
member this.Value = value
override this.Zero() = Euro(0) :> _
Run Code Online (Sandbox Code Playgroud) 为什么内联在这种情况下不起作用?
type TupleBuilder () =
static member inline Cons(a,(b,c)) = (a, b, c)
static member inline Cons(a,(b,c,d)) = (a, b, c, d)
static member inline Cons(a,(b,c,d,e)) = (a, b, c, d, e)
let inline cons h t = TupleBuilder.Cons(h,t)
Run Code Online (Sandbox Code Playgroud)
调用给TupleBuilder.Cons了我以下编译器错误
A unique overload for method 'Cons' could not be determined based on type
information prior to this program point. A type annotation may be needed.
Candidates:
static member TupleBuilder.Cons : a:'a0 * ('a1 * 'a2 * 'a3 * …Run Code Online (Sandbox Code Playgroud) 我正在尝试跟进"Lightweight high-kinded polymorphism"(https://ocamllabs.github.io/higher/lightweight-higher-kinded-polymorphism.pdf)这篇论文并且我坚持将这个ML代码转换为F#
type (_,_) arrow =
Fn_plus : ((int ? int), int) arrow
| Fn_plus_cons : int ? ((int ? int list), int list) arrow
Run Code Online (Sandbox Code Playgroud)
和
let apply : type a b. (a, b) arrow ? a ? b =
fun (appl, v) ? match appl with
| Fn_plus ? let (x, y) = v in x + y
| Fn_plus_cons n ? let (x, l’) = v in x + n :: l’
Run Code Online (Sandbox Code Playgroud)
具体来说,类型定义感觉就像一个巨大的魔力墙.
f# ×6
database ×1
document ×1
elixir ×1
functor ×1
generics ×1
gradle ×1
haskell ×1
interface ×1
ml ×1
polymorphism ×1
purescript ×1
reflection ×1
schema ×1
types ×1