Scalaz(40)- Free :versioned up,再回顾
在上一篇讨论里我在设计示范例子时遇到了一些麻烦。由于Free Monad可能是一种主流的FP编程规范,所以在进入实质编程之前必须把所有东西都搞清楚。前面遇到的问题主要与scalaz Free的FreeC类型有关系。这个类型主要是针对一些非Functor的F[A]特别设计的。FreeC是Coyoneda[F,A]的Free Monad类型,任何F[A]都可以被转换成Coyoneda[F,A],而Coyoneda[F,A]本身是个Functor。因为我们通常都在Functor和非Functor ADT混合应用环境下,所以倾向于通用一些的类型和结构,特别是使用联合语句Coproduct时是不容许不同Free类型的。所以在前面的示范程序里我们只能选用scalaz提供的基于Coyoneda的类型FreeC、升格函数liftFC、及运算函数runFC。最头疼的是使用Coproduct时:Inject的目标语句集G[_]是后置的,在Inject时是否Functor还不明确:
def lift[F[_],G[_],A](fa: F[A])(implicit I: Inject[F,G]): Free.FreeC[G,A] =
Free.liftFC(I.inj(fa))
由于G[_]是否Functor还不明确,唯一选项也就只能是liftFC了。实际上造成FreeC类型麻烦的根本是Free[S[_],A]类型其中一个实例case class Suspend[S[_],A](s: S[Free[S,A]]),这个实例必须用monad的join来运算,因而要求S必须是个Functor,所以这个版本的Free被称为Free for Functor。另一个原因可能是scalaz借鉴了haskell的实现方式。无论如何,为了解决我们遇到的问题,必须想办法绕过S必须是Functor这个门槛。在查找相关资料时发现Cats的Free里根本没有FreeC这个类型。当然也就没有liftFC这么个升格函数了。Cats Free的Suspend形式是不同的:case class Suspend[F[_],A](s: F[A]),这正是我们所想得到的方式。正想着如何用Cats的Free来替代scalaz Free时才发现最新scalaz版本722(前面我一直使用是scalaz v7.1)里面的Free结构定义竟然已经升级了,看来许多其他的scalaz使用者都应该遇到了相同的麻烦。研究了一下前后两个版本的Free结构定义后发现实际上我们可以用另一个方式来代表Free结构:scalaz/Free.scala
sealed abstract class Free[S[_], A] {
final def map[B](f: A => B): Free[S, B] =
flatMap(a => Return(f(a)))
/** Alias for `flatMap` */
final def >>=[B](f: A => Free[S, B]): Free[S, B] = this flatMap f
/** Binds the given continuation to the result of this computation. */
final def flatMap[B](f: A => Free[S, B]): Free[S, B] = gosub(this)(f)
...
/** Return from the computation with the given value. */
private case class Return[S[_], A](a: A) extends Free[S, A]
/** Suspend the computation with the given suspension. */
private case class Suspend[S[_], A](a: S[A]) extends Free[S, A]
/** Call a subroutine and continue with the given function. */
private sealed abstract case class Gosub[S[_], B]() extends Free[S, B] {
type C
val a: Free[S, C]
val f: C => Free[S, B]
}
private def gosub[S[_], B, C0](a0: Free[S, C0])(f0: C0 => Free[S, B]): Free[S, B] =
new Gosub[S, B] {
type C = C0
val a = a0
val f = f0
}
上面这段可以用更简单的方式表达,与下面的结构定义相同:
trait Free[S[_],A]
case class Return[S[_],A](a: A) extends Free[S,A]
case class FlatMap[S[_],A,B](fa: Free[S,A], f: A => Free[S,B]) extends Free[S,B]
case class Suspend[S[_],A](s: S[A]) extends Free[S,A]
我们把Suspend(S[Free[S,A]])变成Suspend(S[A]),增加了一个实例FlatMap。现在这个Suspend状态代表了一步运算,FlatMap状态代表连续运算,FlatMap和Suspend(S[A])加在一起可以替代Suspend(S[Free[S,A]])状态。我们知道Suspend的主要意义是在于对Free结构进行Interpret时对存放在内存里的各种状态进行运算时:如果是Return返回结果、FlatMap是连续运算,那么Suspend就扮演着Free[S,A] => M[A]这么个函数角色了。分析上面的代码不难发现FlatMap就是Gusub。
好了,现在有了这个Suspend我们可以很方便的把任何F[A]升格成Free,这是v722的liftF函数:
/** Suspends a value within a functor in a single step. Monadic unit for a higher-order monad. */
def liftF[S[_], A](value: S[A]): Free[S, A] =
Suspend(value)
上面的描述不正确:a value within a functor 应该是 a value within a type constructor。
在上次的示范例子中遗留下来最需要解决的问题是如何实现多于两种ADT联合语句集的编程,这还是由于联合语句集G[_]是后置的原因。上次遇到的具体问题是无法识别多于两个隐式参数(implicit parameter)、无法编译多于两层的Coproduct、及无法运算(interpret)多于两种联合语句集。在下面我们试试用scalaz722然后设计一套新的编程规范来编写一个由三种ADT组成的Monadic程序:
1、ADTs:
object FreeADTs {
sealed trait Interact[+NextFree]
case class Ask[NextFree](prompt: String, onInput: String => NextFree) extends Interact[NextFree]
case class Tell[NextFree](msg: String, next: NextFree) extends Interact[NextFree]
sealed trait InteractInstances {
object InteractFunctor extends Functor[Interact] {
def map[A,B](ia: Interact[A])(f: A => B): Interact[B] = ia match {
case Ask(prompt,input) => Ask(prompt, input andThen f)
case Tell(msg,next) => Tell(msg, f(next))
}
}
}
sealed trait InteractFunctions {
def ask[G[_],A](p: String, f: String => A)(implicit I: Inject[Interact,G]): Free[G,A] =
Free.liftF(I.inj(Ask(p,f)))
def tell[G[_],A](m: String)(implicit I: Inject[Interact,G]): Free[G,Unit] =
Free.liftF(I.inj(Tell(m,Free.pure(()))))
}
object Interacts extends InteractInstances with InteractFunctions
}
如上所述,我们采用了一种 xxx trait, xxxInstances, xxxFunctions, xxxs 规范。
2、ASTs:
object FreeASTs {
import FreeADTs._
import Interacts._
val interactScript = for {
first <- ask("what's your first name?",identity)
last <- ask("your last name?",identity)
_ <- tell(s"hello, $first $last")
} yield ()
}
3、Interpreter:
object FreeInterps {
import FreeADTs._
object InteractConsole extends (Interact ~> Id) {
def apply[A](ia: Interact[A]): Id[A] = ia match {
case Ask(p,onInput) => println(p); onInput(readLine)
case Tell(m,n) => println(m); n
}
}
}
4、运行:
object FreePrgDemo extends App {
import FreeASTs._
import FreeInterps._
interactScript.foldMapRec(InteractConsole)
}
我们在这里调用了新版本scalaz Free里的foldMapRec函数:
final def foldMapRec[M[_]](f: S ~> M)(implicit M: Applicative[M], B: BindRec[M]): M[A] =
B.tailrecM[Free[S, A], A]{
_.step match {
case Return(a) => M.point(\/-(a))
case Suspend(t) => M.map(f(t))(\/.right)
case b @ Gosub() => (b.a: @unchecked) match {
case Suspend(t) => M.map(f(t))(a => -\/(b.f(a)))
}
}
}(this)
foldMapRec又调用了BindRec typeclass的tailrecM函数:
/**
* [[scalaz.Bind]] capable of using constant stack space when doing recursive
* binds.
*
* Implementations of `tailrecM` should not make recursive calls without the
* `@tailrec` annotation.
*
* Based on Phil Freeman's work on stack safety in PureScript, described in
* [[http://functorial.com/stack-safety-for-free/index.pdf Stack Safety for
* Free]].
*/
////
trait BindRec[F[_]] extends Bind[F] { self =>
//// def tailrecM[A, B](f: A => F[A \/ B])(a: A): F[B]
这个BindRec typeclass可以保证递归运算的堆栈安全。在Free.scala里可以找到BindRec的实例,它具体实现了这个tailrecM函数:
sealed abstract class FreeInstances extends FreeInstances0 with TrampolineInstances with SinkInstances with SourceInstances {
implicit def freeMonad[S[_]]: Monad[Free[S, ?]] with BindRec[Free[S, ?]] =
new Monad[Free[S, ?]] with BindRec[Free[S, ?]] {
override def map[A, B](fa: Free[S, A])(f: A => B) = fa map f
def bind[A, B](a: Free[S, A])(f: A => Free[S, B]) = a flatMap f
def point[A](a: => A) = Free.point(a)
// Free trampolines, should be alright to just perform binds.
def tailrecM[A, B](f: A => Free[S, A \/ B])(a: A): Free[S, B] =
f(a).flatMap(_.fold(tailrecM(f), point(_)))
}
...
有了foldMapRec我们可以放心运算任何规模的AST。下面是运行结果样本:
what's your first name?
tiger
your last name?
chan
hello, tiger chan
现在我们再示范两种ADT的联合语句集编程:
1、ADTs: 增加一个非Functor的ADT UserLogin
sealed trait UserLogin[+A] //非Functor 高阶类
case class CheckId(uid: String) extends UserLogin[Boolean]
case class Login(uid: String, pswd: String) extends UserLogin[Boolean]
sealed trait LoginFunctions {
def checkId[G[_]](uid: String)(implicit I: Inject[UserLogin,G]): Free[G,Boolean] =
Free.liftF(I.inj(CheckId(uid)))
def login[G[_]](uid: String, pswd: String)(implicit I: Inject[UserLogin, G]): Free[G,Boolean] =
Free.liftF(I.inj(Login(uid,pswd)))
}
object Logins extends LoginFunctions
2、ASTs:
import Logins._
type InteractLogin[A] = Coproduct[Interact,UserLogin,A]
val loginScript = for {
uid <- ask[InteractLogin,String]("what's you id?",identity)
idok <- checkId[InteractLogin](uid)
_ <- if (idok) tell[InteractLogin](s"hi, $uid") else tell[InteractLogin]("sorry, don't know you!")
pwd <- if (idok) ask[InteractLogin,String](s"what's your password?",identity)
else Free.point[InteractLogin,String]("")
login <- if (idok) login[InteractLogin](uid,pwd)
else Free.point[InteractLogin,Boolean](false)
_ <- if (login) tell[InteractLogin](s"congratulations,$uid")
else tell[InteractLogin](idok ? "sorry, no pass!" | "")
} yield login
UserLogin需要验证用户编号和密码,我们通过依赖注入来提供验证功能:
object Dependencies {
trait UserControl {
val pswdMap: Map[String,String]
def validateId: Boolean
def validatePassword: Boolean
}
}
3、Interpreter:需要用Reader来注入UserControl依赖。现在的AST是个两种ADT的联合语句集,所以需要符合类型的语法解析函数,并且两种ADT的最终运算环境(context)必须一致用Reader:
import Dependencies._
type AuthReader[A] = Reader[UserControl,A]
object InteractLogin extends (Interact ~> AuthReader) {
def apply[A](ia: Interact[A]): AuthReader[A] = ia match {
case Ask(p,onInput) => println(p); Reader {m => onInput(readLine)}
case Tell(msg,n) => println(msg); Reader {m => n}
}
}
object LoginConsole extends (UserLogin ~> AuthReader) {
def apply[A](ua: UserLogin[A]): AuthReader[A] = ua match {
case CheckId(uid) => Reader {m => m.validateId(uid)}
case Login(uid,pwd) => Reader {m => m.validatePassword(uid, pwd)}
}
}
def or[F[_],H[_],G[_]](f: F~>G, h: H~>G) =
new (({type l[x] = Coproduct[F,H,x]})#l ~> G) {
def apply[A](ca: Coproduct[F,H,A]):G[A] = ca.run match {
case -\/(fg) => f(fg)
case \/-(hg) => h(hg)
}
}
4、运算时把依赖注入:
object FreeDemo extends App {
import FreeASTs._
import FreeInterps._
import Dependencies._
object AuthControl extends UserControl {
val pswdMap = Map (
"Tiger" -> "",
"John" -> ""
)
override def validateId(uid: String) =
pswdMap.getOrElse(uid,"???") /== "???"
override def validatePassword(uid: String, pswd: String) =
pswdMap.getOrElse(uid, pswd+"!") === pswd
}
loginScript.foldMapRec(or(InteractLogin,LoginConsole)).run(AuthControl)
下面是一些测试运行结果:
what's you id?
Tiger
hi, Tiger
what's your password? sorry, no pass!
...
what's you id?
foo
sorry, don't know you!
...
what's you id?
Tiger
hi, Tiger
what's your password? congratulations,Tiger
下面我们在这个基础上再增加一个ADT:Permission
1、ADTs:
sealed trait Permission[+A]
case class HasPermission(uid: String, acc: Int) extends Permission[Boolean]
sealed trait PermissionFunctions {
def hasPermission[G[_]](uid: String, acc: Int)(implicit I: Inject[Permission,G]): Free[G,Boolean] =
Free.liftF(I.inj(HasPermission(uid,acc)))
}
object Permissions extends PermissionFunctions
2、ASTs:
import Permissions._
type InteractLoginPermission[A] = Coproduct[Permission,InteractLogin,A]
type T[A] = InteractLoginPermission[A]
val authScript = for {
uid <- ask[T,String]("what's you id?",identity)
idok <- checkId[T](uid)
_ <- if (idok) tell[T](s"hi, $uid")
else tell[T]("sorry, don't know you!")
pwd <- if (idok) ask[T,String](s"what's your password?",identity)
else Free.point[T,String]("")
login <- if (idok) login[T](uid,pwd)
else Free.point[T,Boolean](false)
_ <- if (login) tell[T](s"congratulations,$uid")
else tell[T](idok ? "sorry, no pass!" | "")
acc <- if (login) ask[T,Int](s"what's your access code, $uid?",_.toInt)
else Free.point[T,Int]()
perm <- if (login) hasPermission[T](uid,acc)
else Free.point[T,Boolean](false)
_ <- if (perm) tell[T](s"you may use the system,$uid")
else tell[T]((idok && login) ? "sorry, you are banned!" | "") } yield ()
这次我们还要通过依赖来验证用户权限Permission,所以需要调整Dependencies:
object Dependencies {
trait UserControl {
val pswdMap: Map[String,String]
def validateId(uid: String): Boolean
def validatePassword(uid: String, pswd: String): Boolean
}
trait AccessControl {
val accMap: Map[String, Int]
def grandAccess(uid: String, acc: Int): Boolean
}
trait Authenticator extends UserControl with AccessControl
}
增加了AccessControl,然后用Authenticator统一它们
3、Interpreters:
import Dependencies._
type AuthReader[A] = Reader[Authenticator,A]
object InteractLogin extends (Interact ~> AuthReader) {
def apply[A](ia: Interact[A]): AuthReader[A] = ia match {
case Ask(p,onInput) => println(p); Reader {m => onInput(readLine)}
case Tell(msg,n) => println(msg); Reader {m => n}
}
}
object LoginConsole extends (UserLogin ~> AuthReader) {
def apply[A](ua: UserLogin[A]): AuthReader[A] = ua match {
case CheckId(uid) => Reader {m => m.validateId(uid)}
case Login(uid,pwd) => Reader {m => m.validatePassword(uid, pwd)}
}
}
// type AccessReader[A] = Reader[AccessControl,A]
object PermConsole extends (Permission ~> AuthReader) {
def apply[A](pa: Permission[A]): AuthReader[A] = pa match {
case HasPermission(uid,acc) => Reader {m => m.grandAccess(uid, acc)}
}
}
def or[F[_],H[_],G[_]](f: F~>G, h: H~>G) =
new (({type l[x] = Coproduct[F,H,x]})#l ~> G) {
def apply[A](ca: Coproduct[F,H,A]):G[A] = ca.run match {
case -\/(fg) => f(fg)
case \/-(hg) => h(hg)
}
}
def among3[F[_],H[_],K[_],G[_]](f: F~>G, h: H~>G, k: K~>G) = {
type FH[A] = Coproduct[F,H,A]
type KFH[A] = Coproduct[K,FH,A]
new (({type l[x] = Coproduct[K,FH,x]})#l ~> G) {
def apply[A](kfh: KFH[A]): G[A] = kfh.run match {
case -\/(kg) => k(kg)
case \/-(cfh) => cfh.run match {
case -\/(fg) => f(fg)
case \/-(hg) => h(hg)
}
}
}
}
调整了依赖类型。增加三种ADT语句集解析函数among3。
4、运算:
object FreeDemo extends App {
import FreeASTs._
import FreeInterps._
import Dependencies._
object AuthControl extends Authenticator {
val pswdMap = Map (
"Tiger" -> "",
"John" -> ""
)
override def validateId(uid: String) =
pswdMap.getOrElse(uid,"???") /== "???"
override def validatePassword(uid: String, pswd: String) =
pswdMap.getOrElse(uid, pswd+"!") === pswd
val accMap = Map (
"Tiger" -> ,
"John" ->
)
override def grandAccess(uid: String, acc: Int) =
accMap.getOrElse(uid, -) > acc
}
authScript.foldMapRec(among3(InteractLogin,LoginConsole,PermConsole)).run(AuthControl)
// loginScript.foldMapRec(or(InteractLogin,LoginConsole)).run(AuthControl)
// interactScript.foldMapRec(InteractConsole)
}
运算结果:
what's you id?
Tiger
hi, Tiger
what's your password? congratulations,Tiger
what's your access code, Tiger? you may use the system,Tiger
Beautiful! 下面是本文示范的完整代码:
package demo.app
import scalaz._
import Scalaz._
import scala.language.implicitConversions
import scala.language.higherKinds
import com.sun.beans.decoder.FalseElementHandler
import java.rmi.server.UID object FreeADTs {
sealed trait Interact[NextFree]
case class Ask[NextFree](prompt: String, onInput: String => NextFree) extends Interact[NextFree]
case class Tell[NextFree](msg: String, next: NextFree) extends Interact[NextFree]
sealed trait InteractInstances {
object InteractFunctor extends Functor[Interact] {
def map[A,B](ia: Interact[A])(f: A => B): Interact[B] = ia match {
case Ask(prompt,input) => Ask(prompt, input andThen f)
case Tell(msg,next) => Tell(msg, f(next))
}
}
}
sealed trait InteractFunctions {
def ask[G[_],A](p: String, f: String => A)(implicit I: Inject[Interact,G]): Free[G,A] =
Free.liftF(I.inj(Ask(p,f)))
def tell[G[_]](m: String)(implicit I: Inject[Interact,G]): Free[G,Unit] =
Free.liftF(I.inj(Tell(m,Free.pure(()))))
}
object Interacts extends InteractInstances with InteractFunctions sealed trait UserLogin[+A] //非Functor 高阶类
case class CheckId(uid: String) extends UserLogin[Boolean]
case class Login(uid: String, pswd: String) extends UserLogin[Boolean]
sealed trait LoginFunctions {
def checkId[G[_]](uid: String)(implicit I: Inject[UserLogin,G]): Free[G,Boolean] =
Free.liftF(I.inj(CheckId(uid)))
def login[G[_]](uid: String, pswd: String)(implicit I: Inject[UserLogin, G]): Free[G,Boolean] =
Free.liftF(I.inj(Login(uid,pswd)))
}
object Logins extends LoginFunctions
sealed trait Permission[+A]
case class HasPermission(uid: String, acc: Int) extends Permission[Boolean]
sealed trait PermissionFunctions {
def hasPermission[G[_]](uid: String, acc: Int)(implicit I: Inject[Permission,G]): Free[G,Boolean] =
Free.liftF(I.inj(HasPermission(uid,acc)))
}
object Permissions extends PermissionFunctions
}
object FreeASTs {
import FreeADTs._
import Interacts._
val interactScript = for {
first <- ask("what's your first name?",identity)
last <- ask("your last name?",identity)
_ <- tell(s"hello, $first $last")
} yield ()
import Logins._
type InteractLogin[A] = Coproduct[Interact,UserLogin,A]
val loginScript = for {
uid <- ask[InteractLogin,String]("what's you id?",identity)
idok <- checkId[InteractLogin](uid)
_ <- if (idok) tell[InteractLogin](s"hi, $uid") else tell[InteractLogin]("sorry, don't know you!")
pwd <- if (idok) ask[InteractLogin,String](s"what's your password?",identity)
else Free.point[InteractLogin,String]("")
login <- if (idok) login[InteractLogin](uid,pwd)
else Free.point[InteractLogin,Boolean](false)
_ <- if (login) tell[InteractLogin](s"congratulations,$uid")
else tell[InteractLogin](idok ? "sorry, no pass!" | "")
} yield login
import Permissions._
type InteractLoginPermission[A] = Coproduct[Permission,InteractLogin,A]
type T[A] = InteractLoginPermission[A]
val authScript = for {
uid <- ask[T,String]("what's you id?",identity)
idok <- checkId[T](uid)
_ <- if (idok) tell[T](s"hi, $uid")
else tell[T]("sorry, don't know you!")
pwd <- if (idok) ask[T,String](s"what's your password?",identity)
else Free.point[T,String]("")
login <- if (idok) login[T](uid,pwd)
else Free.point[T,Boolean](false)
_ <- if (login) tell[T](s"congratulations,$uid")
else tell[T](idok ? "sorry, no pass!" | "")
acc <- if (login) ask[T,Int](s"what's your access code, $uid?",_.toInt)
else Free.point[T,Int]()
perm <- if (login) hasPermission[T](uid,acc)
else Free.point[T,Boolean](false)
_ <- if (perm) tell[T](s"you may use the system,$uid")
else tell[T]((idok && login) ? "sorry, you are banned!" | "") } yield ()
}
object FreeInterps {
import FreeADTs._
object InteractConsole extends (Interact ~> Id) {
def apply[A](ia: Interact[A]): Id[A] = ia match {
case Ask(p,onInput) => println(p); onInput(readLine)
case Tell(m,n) => println(m); n
}
}
import Dependencies._
type AuthReader[A] = Reader[Authenticator,A]
object InteractLogin extends (Interact ~> AuthReader) {
def apply[A](ia: Interact[A]): AuthReader[A] = ia match {
case Ask(p,onInput) => println(p); Reader {m => onInput(readLine)}
case Tell(msg,n) => println(msg); Reader {m => n}
}
}
object LoginConsole extends (UserLogin ~> AuthReader) {
def apply[A](ua: UserLogin[A]): AuthReader[A] = ua match {
case CheckId(uid) => Reader {m => m.validateId(uid)}
case Login(uid,pwd) => Reader {m => m.validatePassword(uid, pwd)}
}
}
object PermConsole extends (Permission ~> AuthReader) {
def apply[A](pa: Permission[A]): AuthReader[A] = pa match {
case HasPermission(uid,acc) => Reader {m => m.grandAccess(uid, acc)}
}
}
def or[F[_],H[_],G[_]](f: F~>G, h: H~>G) =
new (({type l[x] = Coproduct[F,H,x]})#l ~> G) {
def apply[A](ca: Coproduct[F,H,A]):G[A] = ca.run match {
case -\/(fg) => f(fg)
case \/-(hg) => h(hg)
}
}
def among3[F[_],H[_],K[_],G[_]](f: F~>G, h: H~>G, k: K~>G) = {
type FH[A] = Coproduct[F,H,A]
type KFH[A] = Coproduct[K,FH,A]
new (({type l[x] = Coproduct[K,FH,x]})#l ~> G) {
def apply[A](kfh: KFH[A]): G[A] = kfh.run match {
case -\/(kg) => k(kg)
case \/-(cfh) => cfh.run match {
case -\/(fg) => f(fg)
case \/-(hg) => h(hg)
}
}
}
}
}
object Dependencies {
trait UserControl {
val pswdMap: Map[String,String]
def validateId(uid: String): Boolean
def validatePassword(uid: String, pswd: String): Boolean
}
trait AccessControl {
val accMap: Map[String, Int]
def grandAccess(uid: String, acc: Int): Boolean
}
trait Authenticator extends UserControl with AccessControl
}
object FreeDemo extends App {
import FreeASTs._
import FreeInterps._
import Dependencies._
object AuthControl extends Authenticator {
val pswdMap = Map (
"Tiger" -> "",
"John" -> ""
)
override def validateId(uid: String) =
pswdMap.getOrElse(uid,"???") /== "???"
override def validatePassword(uid: String, pswd: String) =
pswdMap.getOrElse(uid, pswd+"!") === pswd val accMap = Map (
"Tiger" -> ,
"John" ->
)
override def grandAccess(uid: String, acc: Int) =
accMap.getOrElse(uid, -) > acc
}
authScript.foldMapRec(among3(InteractLogin,LoginConsole,PermConsole)).run(AuthControl)
// loginScript.foldMapRec(or(InteractLogin,LoginConsole)).run(AuthControl)
// interactScript.foldMapRec(InteractConsole) }
Scalaz(40)- Free :versioned up,再回顾的更多相关文章
- 最近准备把安卓和java的知识再回顾一遍,顺便会写博客上!千变万化还都是源于基础,打扎实基础
最近准备把安卓和java的知识再回顾一遍,顺便会写博客上!千变万化还都是源于基础,打扎实基础,加油吧 距离去北京还有23天
- Linux知识再回顾
Linux再回顾 下面是自己之前centos7的笔记总结第二篇,第一篇是19年就写过了一些,记住Linux中一切皆文件. 这里提下,使用xshell+xftp来使用云服务器是很不错的,强烈建议小伙伴这 ...
- SSM整合再回顾
一.spring 前言:提起spring就不得不说到它的IOC和AOP的概念.IOC就是一个对象容器,程序员可以将对象的创建交给spring的IOC容器来创建,不再使用传统的new对象方式,从而极大程 ...
- python学习日记(编码再回顾)
当想从一种编码方式转换为另一种编码方式时,执行的就是以上步骤. 在python3里面,默认编码方式是unicode,所以无需解码(decode),直接编码(encode)成你想要的编码方式就可以了. ...
- (74)c++再回顾一继承和派生
一:继承和派生 0.默认构造函数即不带参数的构造函数或者是系统自动生成的构造函数.每一个类的构造函数可以有多个,但是析构函数只能有一个. 1.采用公用public继承方式,则基类的公有成员变量和成员函 ...
- STL再回顾(非常见知识点)
目录 为人熟知的pair类型 再谈STL 迭代器的使用 常用的STL容器 顺序容器 vector(向量) 构造方式 拥有的常用的成员函数(java人称方法) string 构造方式 成员函数 dequ ...
- JavaIO再回顾
File类 JavaIO访问文件名和文件检测相关操作 分隔符最好是使用File类提供的File.separator,使程序更加的健壮. File类提供的方法基本上是见名知意,例如getName()就是 ...
- python中os模块再回顾
先看下我的文件目录结构 F:\PYTHON项目\ATM购物车\7月28 在此目录下的文件如下: 封装.py 模块os.sys复习.py 运行当前的文件是模块os.sys复习.py 1.获取当前文件所在 ...
- (转载)ACM训练计划,先过一遍基础再按此拼搏吧!!!!
ACM大量习题题库 ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库. USACO ht ...
随机推荐
- paip. 解决php 以及 python 连接access无效的参数量。参数不足,期待是 1”的错误
paip. 解决php 以及 python 连接access无效的参数量.参数不足,期待是 1"的错误 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源 ...
- VS2012 easyui datagrid url访问之坑
VS2012 easyui datagrid url访问之坑 url属性放的是地址的话 返回的json格式必须有 total 和 rows,如下: {"total":2," ...
- Change Git Default Editor in Windows
On 32 bit Win OS: git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' - ...
- CSS选择器、CSS hack及CSS执行效率
主要内容: 1.CSS选择器.优先级与匹配原理 2. CSS 引入的方式有哪些 ? link 和 @import 的区别是 ? 3.CSS hack 4.如何书高效CSS 一.CSS选择器.优先级与 ...
- Twitter Storm安装配置(Ubuntu系统)单机版
要使用storm首先要安装以下工具:JDK.Python.zookeeper.zeromq.jzmq.storm (注:各个模块都是独立的,如果安装失败或者卡顿可以单独百度某个模块的安装,都是可以的. ...
- Java多线程系列--“基础篇”08之 join()
概要 本章,会对Thread中join()方法进行介绍.涉及到的内容包括:1. join()介绍2. join()源码分析(基于JDK1.7.0_40)3. join()示例 转载请注明出处:http ...
- .NET知识结构
.NET知识结构 .NET介绍 微软.NET战略及技术体系,.NET Framework框架类库(FCL),公共语言运行时(CLR),通用类型系统(CTS),公共语言规范(CLS),程序集(Assem ...
- Windows Azure Web Site (13) Azure Web Site备份
<Windows Azure Platform 系列文章目录> 我们在使用Windows Azure Web Site的时候,经常会遇到需要对Web Site进行备份的情况.在这里笔者简单 ...
- 也说说TIME_WAIT状态
也说说TIME_WAIT状态 一个朋友问到,自己用go写了一个简单的HTTP服务端程序,为什么压测的时候服务端会出现一段时间的TIME_WAIT超高的情况,导致压测的效果不好呢? 记得老王有两篇文章专 ...
- 【Android】Fragment的简单笔记
被虐了,做某公司笔试时,发现自己连个Fragment的生命周期都写不详细.平时敲代码,有开发工具的便利,有网上各大神的文章,就算忘了也很容易的可以查到,但当要自己不借助外界,却发现自己似乎对该知识点并 ...