How to import just specific instances in haskell

I'm facing the following problem: I have multiple instances of a type class defined in a module but don't want to export all of them. How can I do that?

module SomeModule
  ( calculate
  )
where

class Something a where
  calculate :: a -> Int

instance Something Double where
  calculate x = calculate $ roundToInt x

instance Something Int where
  calculate x = doSomething x

roundToInt :: Double -> Int
roundToInt = round

doSomething :: Int -> Int
doSomething _ = 42

In this (simplified) example I have two instances of the type class Something which depend on each other, but I just would like to export the instance for Doubles and not for Ints. But in my example, both instances get exported implicitly. Is there a way around it?



Read more here: https://stackoverflow.com/questions/67013263/how-to-import-just-specific-instances-in-haskell

Content Attribution

This content was originally published by Balazs at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: