小编din*_*ino的帖子

Array在哪里获取其toList方法

通过搜索,我理解将数组转换为List的方式(或方法)是这样的:

val l = Array(1, 2, 3).toList
Run Code Online (Sandbox Code Playgroud)

但是我不仅无法在Array的API文档中找到toList方法,我无法在任何似乎是Array的祖先或继承特征的东西中找到它.

使用较新的2.9 API文档,我看到toList存在于以下内容中:

ImmutableMapAdaptor ImmutableSetAdaptor IntMap List ListBuffer LongMap 
MutableList Option ParIterableLike PriorityQueue Stack StackProxy 
StreamIterator SynchronizedSet SynchronizedStack TraversableForwarder 
TraversableOnce TraversableOnceMethods TraversableProxyLike
Run Code Online (Sandbox Code Playgroud)

但是我无法理解toList如何从其中一个获取成为Array的一部分.有谁能解释一下?

scala

7
推荐指数
1
解决办法
4781
查看次数

什么时候 TypeApplications 比简单的 :: 签名或 ScopedTypeVariables 更受欢迎?

考虑这个模糊类型推断的简单示例:

#! /usr/bin/env stack
{- stack runghc -}

{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

main :: IO ()
main = do
  -- This will fail to compile without additional type info
  -- let w = read "22"
  -- print w
  
  -- My go-to for this is type signatures in the expressions
  let x = read "33" :: Integer
  print x 
  
  -- Another possibility is ScopedtypeVariables
  let y :: Integer = read "44"
  print y
  
  -- How does TypeApplications …
Run Code Online (Sandbox Code Playgroud)

haskell types

3
推荐指数
1
解决办法
80
查看次数

与简单的Scala包装示例混淆

我一直在使用Scala中的包装类和导入包时遇到困惑.让我从一对简单的源文件开始:

档案:a/A.scala

package a

// Which of these imports should be used? They both seem to work.
//import a.b._
import b._

class A {
   val fieldB = new B
}
Run Code Online (Sandbox Code Playgroud)

档案:a/b/B.scala

package a.b

class B
Run Code Online (Sandbox Code Playgroud)

用法

使用scalac进行编译时无需投诉A.scala中的任何导入

尝试在REPL中加载这些文件的方式不同:

$ scala
Welcome to Scala version 2.8.0.r0-b20100714201327 (Java HotSpot(TM) Server VM, Java 1.6.0_20).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :l a/b/B.scala
Loading a/b/B.scala...
<console>:1: error: illegal start of definition
       package a.b
       ^
defined class B …
Run Code Online (Sandbox Code Playgroud)

scala package scala-2.8

2
推荐指数
1
解决办法
3748
查看次数

标签 统计

scala ×2

haskell ×1

package ×1

scala-2.8 ×1

types ×1