小编Chr*_*her的帖子

减少Haskell中的范围

我是Haskell的新手.有人可以解释为什么定义这样的列表会返回一个空列表

ghci>  let myList = [10..1]
ghci>  myList
[]
Run Code Online (Sandbox Code Playgroud)

但是这可以正常工作.

ghci>  let myList = [10, 9..1]
ghci>  myList
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Run Code Online (Sandbox Code Playgroud)

haskell list

19
推荐指数
2
解决办法
6815
查看次数

xsl:使用apply-templates排序而不排序

我有一个很大的XSL文档,用于执行许多操作的赋值.它已接近完成,但我错过了必须进行排序的要求,我无法使其正常工作.这是正在发生的事情的SSCCE.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!--   Root Document    -->
<xsl:template match="/">

    <html>
    <body>

        <xsl:apply-templates select="staff">
            <xsl:sort select="member/last_name" />
        </xsl:apply-templates>

    </body>
    </html>

</xsl:template>

<xsl:template match="member">
    <xsl:value-of select="first_name" />&#160;<xsl:value-of select="last_name" /> <br/>
</xsl:template>

</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

XML文件看起来像这样

<?xml version="1.0" encoding="UTF-8"?>

<?xml-stylesheet type="text/xsl" href="sort.xsl"?>

<staff>
    <member>
        <first_name>Joe</first_name>
        <last_name>Blogs</last_name>
    </member>

    <member>
        <first_name>John</first_name>
        <last_name>Smith</last_name>
    </member>

    <member>
        <first_name>Steven</first_name>
        <last_name>Adams</last_name>
    </member>

</staff>
Run Code Online (Sandbox Code Playgroud)

我期待工作人员按姓氏列出,但他们没有得到排序.请记住,我对XSLT非常缺乏经验.

xslt

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

Structs上的协议扩展导致编译错误"Self"约束为非协议类型

我正在尝试将约束协议扩展应用于结构(Swift 2.0)并接收以下编译器错误:

类型'Self'约束为非协议类型'Foo'

struct Foo: MyProtocol {
    let myVar: String

    init(myVar: String) {
        self.myVar = myVar
    }
}

protocol MyProtocol {
    func bar()
}

extension MyProtocol where Self: Foo {
    func bar() {
        print(myVar)
    }
}

let foo = Foo(myVar: "Hello, Protocol")
foo.bar()
Run Code Online (Sandbox Code Playgroud)

我可以通过更改struct Foo来修复此错误,class Foo但我不明白为什么这样做.为什么我不能将where Self:约束协议作为结构?

swift

12
推荐指数
1
解决办法
3849
查看次数

简单的Haskell程序导致"模式中的非法签名"错误

我决定自学Haskell,我一生都没有这么沮丧.我正在浏览http://lisperati.com/haskell/上的教程,这是我能找到的最简单的教程.我要做的就是读取一个名为people.txt的文本文件,其中包含一个数字列表并打印列表的长度.这段代码直接来自教程.

import Data.List

type Person = [Int]

main = do

    people_text <- readFile "people.txt"
    let people :: [Person]
            people = read people_text

    putStr "Number of people "
    putStr (length people_text)
Run Code Online (Sandbox Code Playgroud)

当我尝试使用runHaskell tutorial03.hs运行该文件时,我收到此错误消息

tutorial03.hs:9:13:
Illegal signature in pattern: [Person] people
    Use -XScopedTypeVariables to permit it
Run Code Online (Sandbox Code Playgroud)

使用XScopedTypeVariables标志我得到

tutorial03.hs:10:17: Not in scope: type variable `people'
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下我做错了什么.

haskell

9
推荐指数
1
解决办法
3648
查看次数

标签 统计

haskell ×2

list ×1

swift ×1

xslt ×1