Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[default_instance] 属性を紹介する #842

Closed
Seasawher opened this issue Sep 20, 2024 · 2 comments · Fixed by #900
Closed

[default_instance] 属性を紹介する #842

Seasawher opened this issue Sep 20, 2024 · 2 comments · Fixed by #900
Assignees

Comments

@Seasawher
Copy link
Member

Seasawher commented Sep 20, 2024

使用例は、OfNat インスタンスをNatではなくて他の集合に移すなど。

def NatPair := Nat × Nat

instance instNatPair : OfNat NatPair 0 := ⟨(0, 0)⟩

/-- info: 0 : Nat -/
#guard_msgs in #check 0

attribute [default_instance] instNatPair

/-- info: 0 : NatPair -/
#guard_msgs in #check 0

TPiLにも例があった気がする

@Seasawher Seasawher changed the title [default_instance] 属性を紹介する [default_instance] 属性を紹介する Sep 20, 2024
@Seasawher
Copy link
Member Author

TPiL における [default_instance] の使用例

namespace Hidden

class HMul (α : Type u) (β : Type v) (γ : outParam (Type w)) where
  hMul : α → β → γ

export HMul (hMul)

instance instHMulInt : HMul Int Int Int where
  hMul := Int.mul

-- Error "typeclass instance problem is stuck, it is often due to metavariables HMul ?m.89 ?m.90 ?m.91"
-- `y` の型を明示的に与えればエラーは消える
#check_failure fun y => (fun x => x * y)

attribute [default_instance] instHMulInt

#check fun y => (fun x => x * y)

end Hidden

@Seasawher
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant