无法为关联数据族派生Typeable(Cannot derive Typeable for associated data family)
我正在尝试为相关数据系列派生
Typeable
,如下所示:{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE TypeFamilies #-} module Test where import Data.Typeable class Test a where data DTest a :: * instance Test () where data DTest () = Foo deriving Typeable
但我收到以下错误消息,它让我有点困惑:
[1 of 1] Compiling Test ( test.hs, test.o ) test.hs:12:14: Cannot eta-reduce to an instance of form instance (...) => Typeable DTest In the data instance declaration for ‘DTest’
有人可以详细说明这里出了什么问题吗?
I'm trying to derive
Typeable
for an associated data family like so:{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE TypeFamilies #-} module Test where import Data.Typeable class Test a where data DTest a :: * instance Test () where data DTest () = Foo deriving Typeable
But I'm getting the following error message and it leaves me a little puzzled:
[1 of 1] Compiling Test ( test.hs, test.o ) test.hs:12:14: Cannot eta-reduce to an instance of form instance (...) => Typeable DTest In the data instance declaration for ‘DTest’
Could someone please elaborate as to what is going wrong here?
原文:https://stackoverflow.com/questions/29994790
更新时间:2023-11-28 22:11
最满意答案
一些基于正则表达式的预处理怎么样?
示例
input.html
:<html> <head> <title>My example</title> </head> <body> <h1>Test</h1> <div id="foo"> </div> <script type="text/javascript"> document.getElementById('foo').innerHTML = '<span style="color:red;">Hello World!</span>'; </script> </body> </html>
脚本标记删除PHP脚本:
<?php // unformatted source output: header("Content-Type: text/plain"); // read the example input file given above into a string: $input = file_get_contents('input.html'); echo "Before:\r\n"; echo $input; echo "\r\n\r\n-----------------------\r\n\r\n"; // replace script tags including their contents by "" $output = preg_replace("~<script[^<>]*>.*</script>~Uis", "", $input); echo "After:\r\n"; echo $output; echo "\r\n\r\n-----------------------\r\n\r\n"; ?>
How about some regex-based pre-processing?
Example
input.html
:<html> <head> <title>My example</title> </head> <body> <h1>Test</h1> <div id="foo"> </div> <script type="text/javascript"> document.getElementById('foo').innerHTML = '<span style="color:red;">Hello World!</span>'; </script> </body> </html>
Script tag removing php script:
<?php // unformatted source output: header("Content-Type: text/plain"); // read the example input file given above into a string: $input = file_get_contents('input.html'); echo "Before:\r\n"; echo $input; echo "\r\n\r\n-----------------------\r\n\r\n"; // replace script tags including their contents by "" $output = preg_replace("~<script[^<>]*>.*</script>~Uis", "", $input); echo "After:\r\n"; echo $output; echo "\r\n\r\n-----------------------\r\n\r\n"; ?>
相关问答
更多-
因为这个问题是用正则表达式标记的,所以我将在这种情况下回答穷人的解决方案: $html = preg_replace('##is', '', $html); 然而,正则表达式不是用于解析HTML / XML,即使你写出完美的表达式,它最终会破坏,但这不值得,但是在某些情况下,快速修复一些标记是有用的,而且与快速修复一样,忘记安全 仅对您信任的内容/标记使用正则表达式。 请记住,用户输入的任何内容应被视为不安全 。 更好的解决方案是使用为此设计的DOMD ...
-
尝试这一点,注意到HTML的语法太复杂,正常表达式在100%的时间是正确的: var regex = /(<([^>]+)>)/ig , body = "
test
" , result = body.replace(regex, ""); console.log(result); 如果您愿意使用jQuery等库,您可以简单地执行此操作: console.log($('test
').text()); Try this, noting that the grammar o ... -
一些基于正则表达式的预处理怎么样? 示例input.html :
My example Test
如果字符串相当小,则您拥有的一个选项是使用正则表达式。 String.replaceAll接受正则表达式和替换字符串。 所以你可以试试像yourString=yourString.replaceAll("style=\\".+?\\"", ""); yourString=yourString.replaceAll("class=\\".+?\\"", ""); 试试http://gskinner.com/RegExr/它在一个示例字符串上有一个很棒的正则表达式构建器asnd求值器。 If the strin ...更新列以删除html标记(update column to remove html tags)[2022-11-30]
UDF代表“用户定义的函数” - 除非您没有使用名称“udf_StripHTML”定义函数,否则这根本不起作用。 我想你参考这个函数: CREATE FUNCTION [dbo].[udf_StripHTML] (@HTMLText VARCHAR(MAX)) RETURNS VARCHAR(MAX) AS BEGIN DECLARE @Start INT DECLARE @End INT DECLARE @Length INT SET @Start = CHARINDEX('<',@HTMLText) S ...删除脚本中的HTML标签(Remove HTML tags in script)[2021-09-11]
这个正则表达式/ <{1} [^ <>] {1,}> {1} / g应该用一个空格替换这两个<>和括号之间的字符串中的任何文本。 这个 var str = "How are you