Zulip Chat Archive
Stream: new members
Topic: Constrain type
Miguel Negrão (Mar 22 2023 at 15:39):
In the type signature of a function, how can I restrict a type to any type which is an instance of a particular type class, such as a Monad ?
Kevin Buzzard (Mar 22 2023 at 15:40):
Ask for [Monad X]
?
Miguel Negrão (Mar 22 2023 at 15:52):
This example is a bit silly, but how would I constrain m such that it must be a Monad ?
def A (m : Type → Type) (y : Type) : Type := m y
I don't quite get how to use the [ ] syntax you mention. Thanks !
Miguel Negrão (Mar 22 2023 at 15:57):
Ok, I think I got it !
def A (m : Type → Type) [Monad m] (y : Type) : Type := m y
Last updated: Dec 20 2023 at 11:08 UTC