斯卡拉兹:没有找到幺半群

时间:2016-05-05 22:05:35

标签: scala scalaz

我正在关注此scalaz教程:http://eed3si9n.com/learning-scalaz/FoldLeft.html

2016-05-05 21:58:47 Connection: opening to mail.myserver.com:587, timeout=300, options=array (
                                      )
2016-05-05 21:58:47 Connection: opened
2016-05-05 21:58:52 SMTP -> get_lines(): $data is ""
2016-05-05 21:58:52 SMTP -> get_lines(): $str is  "220 sys.myserver.com ESMTP Exim 4.72 Thu, 05 May 2016 17:58:50 -0400
                                      "
2016-05-05 21:58:52 SERVER -> CLIENT: 220 sys.myserver.com ESMTP Exim 4.72 Thu, 05 May 2016 17:58:50 -0400
2016-05-05 21:58:52 CLIENT -> SERVER: EHLO localhost
2016-05-05 21:58:52 SMTP -> get_lines(): $data is ""
2016-05-05 21:58:52 SMTP -> get_lines(): $str is  "250-sys.myserver.com Hello ***********]
                                      "
2016-05-05 21:58:52 SMTP -> get_lines(): $data is "250-sys.myserver.com Hello cpc68331-cdif16-2-0-cust906.5-1.cable.virginm.net [86.3.207.139]
                                      "
2016-05-05 21:58:52 SMTP -> get_lines(): $str is  "250-SIZE 52428800
                                      "
2016-05-05 21:58:52 SMTP -> get_lines(): $data is "250-sys.myserver.com Hello cpc68331-cdif16-2-0-cust906.5-1.cable.virginm.net [86.3.207.139]
                                      250-SIZE 52428800
                                      "
2016-05-05 21:58:52 SMTP -> get_lines(): $str is  "250-PIPELINING
                                      "
2016-05-05 21:58:52 SMTP -> get_lines(): $data is "250-sys.myserver.com Hello ***************************]
                                      250-SIZE 52428800
                                      250-PIPELINING
                                      "
2016-05-05 21:58:52 SMTP -> get_lines(): $str is  "250-AUTH PLAIN LOGIN
                                      "
2016-05-05 21:58:52 SMTP -> get_lines(): $data is "250-sys.myserver.com Hello ****************************]
                                      250-SIZE 52428800
                                      250-PIPELINING
                                      250-AUTH PLAIN LOGIN
                                      "
2016-05-05 21:58:52 SMTP -> get_lines(): $str is  "250-STARTTLS
                                      "
2016-05-05 21:58:52 SMTP -> get_lines(): $data is "250-sys.myserver.com Hello ******************]
                                      250-SIZE 52428800
                                      250-PIPELINING
                                      250-AUTH PLAIN LOGIN
                                      250-STARTTLS
                                      "
2016-05-05 21:58:52 SMTP -> get_lines(): $str is  "250 HELP
                                      "
2016-05-05 21:58:52 SERVER -> CLIENT: 250-sys.myserver.com Hello ***************]
                                      250-SIZE 52428800
                                      250-PIPELINING
                                      250-AUTH PLAIN LOGIN
                                      250-STARTTLS
                                      250 HELP
2016-05-05 21:58:52 CLIENT -> SERVER: STARTTLS
2016-05-05 21:58:52 SMTP -> get_lines(): $data is ""
2016-05-05 21:58:52 SMTP -> get_lines(): $str is  "220 TLS go ahead
                                      "
2016-05-05 21:58:52 SERVER -> CLIENT: 220 TLS go ahead
2016-05-05 21:58:52 SMTP Error: Could not connect to SMTP host.
2016-05-05 21:58:52 CLIENT -> SERVER: QUIT
2016-05-05 21:58:53 SMTP -> get_lines(): $data is ""
2016-05-05 21:58:53 SMTP -> get_lines(): $str is  "����221 sys.myserver.com closing connection
                                      "
2016-05-05 21:58:53 SMTP -> get_lines(): $data is "����221 sys.myserver.com closing connection
                                      "
2016-05-05 21:58:53 SMTP -> get_lines(): $str is  ""
2016-05-05 21:58:53 SERVER -> CLIENT: ����221 sys.myserver.com closing connection
2016-05-05 21:58:53 SMTP ERROR: QUIT command failed: ����221 sys.myserver.com closing connection


----------


2016-05-05 21:58:53 Connection: closed
2016-05-05 21:58:53 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
{"success":1,"id":"3391"}

这显示输入到scala sbt控制台,但我试图在独立的scala文件中运行它:

scala> object FoldLeftList {
         def foldLeft[A, B](xs: List[A], b: B, f: (B, A) => B) = xs.foldLeft(b)(f)
       }
defined module FoldLeftList

scala> def sum[A: Monoid](xs: List[A]): A = {
         val m = implicitly[Monoid[A]]
         FoldLeftList.foldLeft(xs, m.mzero, m.mappend)
       }
sum: [A](xs: List[A])(implicit evidence$1: Monoid[A])A

但我收到编译错误:

object main extends App {

  trait FoldLeft[F[_]] {
    def foldLeft[A, B](xs: F[A], b: B, f: (B, A) => B): B
  }
  object FoldLeft {
    implicit val FoldLeftList: FoldLeft[List] = new FoldLeft[List] {
      def foldLeft[A, B](xs: List[A], b: B, f: (B, A) => B) = xs.foldLeft(b)(f)
    }
  }

  def sum[M[_]: FoldLeft, A: Monoid](xs: M[A]): A = {
    val m = implicitly[Monoid[A]]
    val fl = implicitly[FoldLeft[M]]
    fl.foldLeft(xs, m.mzero, m.mappend)
  }

}

是否应该导入Monoid?如果是,那么?

更新:

似乎我错过了Monoid def:

[error] \src\main\scala\custom.scala:12: not found: type Monoid
[error]   def sum[M[_]: FoldLeft, A: Monoid](xs: M[A]): A = {
[error]                              ^
[error] \src\main\scala\custom.scala:13: not found: type Monoid
[error]     val m = implicitly[Monoid[A]]
[error]                        ^

1 个答案:

答案 0 :(得分:2)

scalaz导入的标准是import scalaz._, Scalaz._。您可以稍后删除Scalaz._部分,然后选择您需要的内容。