试图在Haskell中抛出异常:
import Control.Exception
import Data.Typeable
data MyException = ThisException | ThatException deriving (Show, Typeable)
instance Exception MyException
data CellPos = CellPos Int Int deriving (Show, Read)
test :: String -> IO CellPos
test str = do
{
if length str == 0
then
throw ThisException;
else
return (CellPos 0 0);
}
Run Code Online (Sandbox Code Playgroud)
编译说:
Can't make a derived instance of `Typeable MyException':
You need -XDeriveDataTypeable to derive an instance for this class
In the data type declaration for `MyException'
Run Code Online (Sandbox Code Playgroud)
我怎么解决它?
您是否还可以编写在调用测试函数时如何捕获此类异常?
我有html文件String,我想使用更新查询将其插入MySQL数据库.我试过这个:
Statement st = connection.createStatement();
String query = "UPDATE orders SET status='ready', html='"+html+"' WHERE id='123'";
int num = st.executeUpdate(query);
Run Code Online (Sandbox Code Playgroud)
但我得到以下例外:
MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'zglosBladWindow').ck_window.showCenter('this');" href="#">zg?o? b??d na stronie<' at line 1
Run Code Online (Sandbox Code Playgroud)
这是在HTML内部 - 可能我只是引用html ""并插入它,因为它包含许多特殊字符和引号也 - 所以我如何插入它?我应该以某种方式编码吗?
我有以下表格:
<form enctype="multipart/form-data" method="post" accept-charset="utf-8">
<input type="file" name="data[MyModel][myfiles]" multiple="multiple">
</form>
Run Code Online (Sandbox Code Playgroud)
当我选择多个文件并提交时$this->request->data['MyModel']['myfiles']只包含最后选择的文件而不是多个... $_FILES还包含最后选择的文件...
我做错了什么?
我有Backbone驱动的单页应用程序.应用程序包含几个文件:
index.html
javascripts/app.js
javascripts/vendor.js
stylesheets/app.css
images/ -> image assets
Run Code Online (Sandbox Code Playgroud)
我想为prerender.io我的应用添加服务,使其对SEO友好.对我这样做最简单的方法是使用express.js托管heroku:
var express = require('express');
var app = express();
app.use(require('prerender-node').set('prerenderToken', 'YOUR_TOKEN'));
// ...
app.listen(process.env.PORT || 5000);
Run Code Online (Sandbox Code Playgroud)
但也许express或实际上node不是最好的服务静态文件?也许heroku不是最好的服务静态文件?什么是最好的解决方案?您有什么推荐的吗?
我有 3 个模型(表),它们的一半属性(列)完全相同(相同的数据类型)。是否可以使用 Postgres 表继承来避免在每个模型(表)中重新输入这些字段?
可以“共享”的示例字段:
title
subtitle
slug
description
seoTile
seoDescription
...
Run Code Online (Sandbox Code Playgroud) 我的firebase看起来像这样:

这是测试代码(咖啡脚本):
Firebase = require 'firebase'
ref = new Firebase 'https://my_firebase.firebaseio.com/items'
ref.once 'child_added', (snapshot) ->
childRef = snapshot.ref()
console.log "child_added", childRef.toString(), snapshot.val()
childRef.transaction(
(data) ->
console.log 'transaction on data', data
return if !data or data.my_key isnt 'my_val'
data.my_key = 'new_val'
return data
,
(err, commited, snapshot) ->
if err
console.error 'error', err
return
console.log 'commited? '+commited
console.log 'server data', snapshot.val()
,
false
)
Run Code Online (Sandbox Code Playgroud)
并输出:
child_added https://my_firebase.firebaseio.com/items/item1 { my_key: 'my_val' }
transaction on data null
commited? false
server data null
Run Code Online (Sandbox Code Playgroud)
当第三个参数 …
我有一个以下的任务:
我必须在Haskell中编写程序,这将允许我创建像excel表一样的东西.有列和行,每个单元格可以包含数字或字符串或某些函数(求和,平均,乘法等).每个函数都将参数列为求和的单元格列表等.
现在我想弄清楚如何将这些数据存储到我的程序中...我正在考虑这样的事情:
data CellPos = CellPos Int Int -- row and col of Cell
data DataType = Text | String | SumFunction | ...... deriving (Enum)
data Cell = Cell CellPos DataType -- but here is a problem , how to put here data with type which depends on DataType???
Run Code Online (Sandbox Code Playgroud)
我想要有一个大的列表Cell并在其中搜索指定的列/行等
但必须有一些更好的解决方案 - 也许一些二维数组自动调整其大小或什么?
我将不得不将文件保存/加载到文件中...
我有这个:
data SomeData = SomeData Int Int
getDataFromUser :: SomeData
getDataFromUser = do
{
read (getLine)::SomeData;
}
Run Code Online (Sandbox Code Playgroud)
这不编译:预期类型字符串实际类型IO字符串
我怎么解决它?我需要这个数据反序列化...
我有username和password我想计算AuthorizationHTTP基本身份验证的标头。计算的标头如下所示:'Basic xyz123xxx'。npm中是否有一个节点软件包可以使我做到这一点?
我正在使用 Aes.Gcm 加密,但 Mac OS 上的默认 OpenSSL 版本似乎不支持它,并且出现以下错误:
System.PlatformNotSupportedException: Algorithm 'AesGcm' is not supported on this platform.
Run Code Online (Sandbox Code Playgroud)
所以我安装了 OpenSSL 3,并brew instal openssl按照我运行的自制程序的建议:
$ echo 'export PATH="/usr/local/opt/openssl@3/bin:$PATH"' >> /Users/user/.bash_profile
Run Code Online (Sandbox Code Playgroud)
不,当我openssl version在终端输入时,我得到:
OpenSSL 3.0.1 14 Dec 2021 (Library: OpenSSL 3.0.1 14 Dec 2021)
Run Code Online (Sandbox Code Playgroud)
但是我不知道如何强制 .Net Core 使用这个 OpenSSL 版本。我遇到了同样的错误,所以我想 .Net 不知道要加载哪个 OpenSSL (默认的 OpenSSL 仍然存在 - LibreSSL 2.8.3。它只是被 .bash_profile 中的 PATH 覆盖)。
我如何告诉 .Net 编译器(或运行时?)加载 OpenSSL v3?我正在使用net6.0Jetbrains Rider IDE(也许我可以以某种方式在 IDE 中设置 Openssl 版本/路径)。
我想解析String以获取Int,我使用它:
string2int :: String -> Int
string2int str = read str::Int
Run Code Online (Sandbox Code Playgroud)
现在我想尽可能地将备用异常/错误视为SIMPLY.我试过了:
import qualified Control.Exception as E
eVal <- try (print (string2int "a")) :: IO (Either E.SomeException ())
case eVal of
Left e -> do { putStrLn "exception"; }
Right n -> do { putStrLn "good"; }
Run Code Online (Sandbox Code Playgroud)
但编译说couldn't match expected type 'E.SomeException()'
with actual type E.IOException.
我究竟做错了什么?
好吧我不知道如何使用它来解决我的问题:我想要这样的事情:
loadfunction = do
{
x <- string2int getLine
if( failed parsing int ) call somefunction
y <- string2int getLine
if( …Run Code Online (Sandbox Code Playgroud)