首页 \ 问答 \ 无法为关联数据族派生Typeable(Cannot derive Typeable for associated data family)

无法为关联数据族派生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">&nbsp;</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">&nbsp;</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";

?>

相关问答

更多