codesnippets:fnowarnorphans
{-# OPTIONS_GHC -fno-warn-orphans #-}
- prevents warnings of orphan instance, meaning:
- instance declaration of a type is not declared in the module of the class
- NOTE: Orphan instances may be useful.
- see also Haskell wiki - Orphan instance
- NOTE: The purpose of the examples here is only to demonstrate the impact on the compiler. The examples may not make sense as a use case of type classes.
- example that may make more sense: Creating data structures from symbol trees
- example:
- code of module Lib:
module Lib ( MyClass(..) ) where class Num x => MyClass x where fMy :: x -> x
- compiler warning, when using -Wall:
app\Main.hs:6:1: warning: [-Worphans] Orphan instance: instance MyClass Double To avoid this move the instance declaration to the module of the class or of the type, or wrap the type with a newtype and declare the instance on the new type. | 6 | instance MyClass Double where | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
- example, with GHC option:
- compiles, error and warning free, with compiler: GHC 8.10.4, using compiler option -Wall
- executes, with output:
15.959999999999999
✎
You could leave a comment if you were logged in.
codesnippets/fnowarnorphans.txt · Last modified: by 127.0.0.1
