首页 \ 问答 \ 不存在量化方法时重叠实例错误的原因(Reason for overlapping instances error when not quantifying method existentially)

不存在量化方法时重叠实例错误的原因(Reason for overlapping instances error when not quantifying method existentially)

给定以下代码,从go类型中删除forall ar失败,并显示“Typeable(D r)重叠实例”。 我想知道为什么?

{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
module M where

import Data.Typeable (Proxy, Typeable, cast)

class C r where
    data D r :: *

deriving instance Typeable D

data A = forall r . A (D r)

go :: forall r a . (Typeable a, Typeable (D r)) => a -> Proxy r -> A
go a _ = case cast a of
  Just (b :: D r) -> A b
  Nothing -> error "fail to cast"

该错误还说“选择取决于r的实例化” - 但是不是由提供的Proxy r固定的?


Given the following code, removing forall a r from the type of go fails with "Overlapping instances for Typeable (D r)". I wonder why?

{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
module M where

import Data.Typeable (Proxy, Typeable, cast)

class C r where
    data D r :: *

deriving instance Typeable D

data A = forall r . A (D r)

go :: forall r a . (Typeable a, Typeable (D r)) => a -> Proxy r -> A
go a _ = case cast a of
  Just (b :: D r) -> A b
  Nothing -> error "fail to cast"

The error also says "The choice depends on the instantiation of r" - but isn't that pinned by the supplied Proxy r?


原文:https://stackoverflow.com/questions/31114770
更新时间:2022-02-10 15:02

最满意答案

希望这可以帮助!

使用bootstrap beforeShowDay选项启用日期。

$(function() {
var datesEnabled = ['2017-9-10', '2017-9-15', '2017-9-25'];
$('#datepicker').datepicker({
format: 'yyyy-mm-dd',
beforeShowDay: function (date) {
  var allDates = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
  if(datesEnabled.indexOf(allDates) != -1)
  return true;
  else
  return false;
   }
});
});
td.day.disabled {
opacity: 0.2;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/js/bootstrap-datepicker.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<input id="datepicker">


Hope this helps!

use bootstrap beforeShowDay option to enable dates.

$(function() {
var datesEnabled = ['2017-9-10', '2017-9-15', '2017-9-25'];
$('#datepicker').datepicker({
format: 'yyyy-mm-dd',
beforeShowDay: function (date) {
  var allDates = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
  if(datesEnabled.indexOf(allDates) != -1)
  return true;
  else
  return false;
   }
});
});
td.day.disabled {
opacity: 0.2;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/js/bootstrap-datepicker.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<input id="datepicker">

相关问答

更多
  • 根据jQueryUI的Datepicker API, 这解释了原因 $("#dateRetrait").datepicker({beforeShowDay: function(d) { console.log("bsd"); alert("bsd"); }}); 不起作用。 另外我注意到你正在调用.datepicker()多次,每次你给它不同的参数。 代替: $("#dateRetrait").datepicker(); $("#dateRetrait").dat ...
  • 正如你在问题中所说,在beforeShowDay可以返回一个具有以下属性的对象:...在你的情况下你的beforeShowDay返回一个Array 。 如果使用上述属性将返回值更改为Object ,则将具有以下代码: $datepicker = $('.input-group.date'); $datepicker.datepicker({ beforeShowDay: function(date) { return { enabled: true, class ...
  • 我找到了答案。 我认为它之所以起作用的原因是因为datepicker函数无法读取day1变量的值。 因此,我没有在datepicker的返回中返回day1变量,而是像这样返回elements.val()“return [day == $('#DayForReg1')。val()]” I found the answer. I think the reason why it didn't work at first because datepicker function can't read the valu ...
  • 第一个错误,你在bootstrap-datepicker之后定义了jquery。 datepicker很可能依赖于jquery。 第二个错误,你的脚本已经准备好了,所以在脚本运行时div不存在。 最好在head部分有引用,并记住顺序很重要,并将脚本放在body部分的底部,这样你就可以确保你的dom元素按时加载了。
  • 好吧我修好了它真的很容易XD,我和旧版本的bootstrap datepicker。 这个版本没有支持BeforeShowDay! 我现在有了一个更新的版本,一切正常! Alright i fixed it it was really easy XD, i had and old version of bootstrap datepicker. This version didnt support BeforeShowDay! I now got a newer version and it all wor ...
  • 希望这可以帮助! 使用bootstrap beforeShowDay选项启用日期。 $(function() { var datesEnabled = ['2017-9-10', '2017-9-15', '2017-9-25']; $('#datepicker').datepicker({ format: 'yyyy-mm-dd', beforeShowDay: function (date) { var allDates = date.getFullYear() + '-' + (date ...
  • 您可以使用jQuery.inArray代替jQuery.each。 要将date参数转换为'yy-mm-dd'格式,您可以使用moment.js。 片段: var date = new Date(); var forbiddeneDates = ['16-12-18','16-12-19','16-12-20']; $('.date').datepicker({ format: 'dd-mm-yyyy', startDate: date, autoclose: true, ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)