我是Haskell的初学者.我正在尝试使用该markdown库来转换mardown并将其插入由Blaze制作的网页中.我可以做这个:
readme :: Html
readme = do
markdown def "#test"
Run Code Online (Sandbox Code Playgroud)
哪个工作正常.但我不能这样做:
readme :: Html
readme = do
readmeFile <- readFile "../README.md"
markdown def readmeFile
Run Code Online (Sandbox Code Playgroud)
因为我得到错误:
Views/Home.hs:55:17: error:
• Couldn't match type ‘IO’ with ‘Text.Blaze.Internal.MarkupM’
Expected type: Text.Blaze.Internal.MarkupM String
Actual type: IO String
• In a stmt of a 'do' block: readmeFile <- readFile "../README.md"
In the expression:
do { readmeFile <- readFile "../README.md";
markdown def readmeFile }
In an equation for ‘readme’:
readme
= do { readmeFile <- …Run Code Online (Sandbox Code Playgroud) 哈斯克尔初学者在这里,对于这个愚蠢的问题提前抱歉.我来自Python,只是想知道如何从Haskell数据类型中获取数据(即字符串).
假设我使用的是RDF图rdf4h,我可以从中获取一个Node对象.这就是我的print样子:
LNode (PlainL "Stories from the Italian Poets: with Lives of the Writers, Volume 1")
Run Code Online (Sandbox Code Playgroud)
如何从中获取字符串值?(即,"来自...的故事")我搜索了Hoogle,:: Node -> Text但我似乎无法找到任何东西.我似乎也无法在Data.RDF.Types或类似的任何地方找到合适的函数.我确信这里有一些非常明显的东西.
我想在python 2.7中替换列表中的部分字符串,但这不符合我的预期:
>>> list = ['apples', 'oranges', 'bananas']
>>> for item in list:
... item=item.replace('app', 'spam')
...
>>> list
['apples', 'oranges', 'bananas']
Run Code Online (Sandbox Code Playgroud)
我期望输出为:['spamles', 'oranges', 'bananas'].
做上述事情的正确方法是什么?我知道我可以创建一个新列表,并将每个项目单独添加到新列表中,但这听起来像很多工作,可能需要两倍的内存.
我想放弃使用pxCSS中的单位并转向使用em单位.此页面有一个转换公式,1/16*X其中16是基本字体大小(以像素为单位),X是要转换的字体大小.考虑到这一点,我尝试做类似的事情:
:%s/\(\d\+\)px/\=1\/16*submatch(1)."em"/gc
Run Code Online (Sandbox Code Playgroud)
但它没有按预期工作.这是我第一次在vim替换中使用表达式,所以我有点迷失.
所以我将浏览CmdArgs文档中的示例,并且我正在尝试构建Hello World程序,以便创建一个简单的CLI程序,该程序将文件名作为输入,并显示该文件的内容(如cat).但我是Haskell的初学者,几乎不知道我在做什么.这是我到目前为止所拥有的:
{-# LANGUAGE DeriveDataTypeable #-}
module ShowFile where
import System.Console.CmdArgs
data ShowFile = ShowFile {file :: Maybe FilePath}
deriving (Show, Data, Typeable)
showFile = ShowFile
{file = def &= typ "FILE" &= argPos 0}
main = print =<< cmdArgs showFile
Run Code Online (Sandbox Code Playgroud)
所以跑步runhaskell mycat.hs test.txt表明:
ShowFile {file = Just "test.txt"}
Run Code Online (Sandbox Code Playgroud)
有些东西在起作用!现在如何让它显示内容test.txt呢?我一直在尝试这样的事情:
main = getContents showFile
Run Code Online (Sandbox Code Playgroud)
但还没有发现正确的事情.
如果我想使用readFilefrom Data.Text.IO,但是readFilePrelude中已经存在,我该如何导入它,这样就不会导致歧义错误?
我有一个脚本,只是说import Data.Text.IO,然后使用readFile,我正在ghci使用:load它测试它,但它抱怨模糊的函数调用.
说我有两个清单,
one = ['a1', 'b1', 'c1']
two = ['a2', 'b2', 'c2']
Run Code Online (Sandbox Code Playgroud)
我想生成这些项目的所有可能组合的集合,而不更改它们在各自列表中的位置.所以对于上面的例子,它是:
['a1', 'b1', 'c1']
['a1', 'b1', 'c2']
['a1', 'b2', 'c2']
['a2', 'b1', 'c1']
['a2', 'b2', 'c1']
['a2', 'b2', 'c2']
Run Code Online (Sandbox Code Playgroud)
我正在寻找itertools希望找到符合此描述的东西,但我还没找到.
我很难让文件上传在php中工作.
预期:有关上传文件的信息.得到:空$ _FILES
这是我的表格/剧本.我究竟做错了什么?
<!DOCTYPE html>
<html lang="en">
<body>
<?php
if($_SERVER['REQUEST_METHOD'] !== "POST"): ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label for="file">Upload a file:</label>
<input type="file" name="file" id="file"><br/>
<button type="submit">Analyze</button>
</form>
<?php endif; ?>
<?php if($_SERVER['REQUEST_METHOD'] == "POST"):
print_r($_FILES); // debugging
if ($_FILES["file"]["size"] < 20000)
{
if ($_FILES["file"]["error"] > 0)
{
echo "<p>Error: " . $_FILES["file"]["error"] . "</p>";
}
else
{
echo "<p>Upload: " . $_FILES["file"]["name"] . "</p>";
echo "<p>Type: " . $_FILES["file"]["type"] . "</p>"; …Run Code Online (Sandbox Code Playgroud)