Reputation: 133
Assume, you have a class:
class AClass a where
func:: Int
instance AClass SomeTree where
func = 0
instance AClass Double where
func = 1
How do I call the function func?
Upvotes: 0
Views: 101
Reputation: 120711
{-# LANGUAGE AllowAmbiguousTypes, TypeApplications #-}
class AClass a where
func :: Int
instance AClass SomeTree where
func = 0
instance AClass Double where
func = 1
foo :: Int
foo = func @SomeTree + func @Double
{-# LANGUAGE ScopedTypeVariables, UnicodeSyntax #-}
bar :: ∀ a . AClass a => a -> Int
bar _ = func @a
Upvotes: 7