[Haskell-cafe] bracket and type family

Henning Thielemann lemming at henning-thielemann.de
Mon Mar 14 13:32:30 UTC 2022


On Mon, 14 Mar 2022, PICCA Frederic-Emmanuel wrote:

> So I try with something simple
>
> --  File
>
> newtype H5FilePath = H5FilePath FilePath
>
> instance DataResource H5FilePath where
>  data OpenedDataResource H5FilePath = File
>  acquireDataResource (H5FilePath f) = openFile (pack f) [ReadOnly] Nothing
>  releaseDataResource = closeFile 
>
> but I end up with this sort of error

It means that openFile returns File type but your instance requires that 
it returns OpenedDataResource H5FilePath. That is, you must wrap the 
result of openFile in the File data constructor.

I.e.:

   acquireDataResource (H5FilePath f) =
     File <$> openFile (pack f) [ReadOnly] Nothing
   releaseDataResource (File f) = closeFile f

Since you used "data" instead of "type" in your type class, your data 
types are custom types per instance.


More information about the Haskell-Cafe mailing list