User Tools

Site Tools


codesnippets:fnowarnorphans

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
codesnippets:fnowarnorphans [2021/04/10 20:45] – created f2b216codesnippets:fnowarnorphans [2025/10/08 00:48] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== {-# OPTIONS_GHC -fno-warn-orphans #-} ====== ====== {-# OPTIONS_GHC -fno-warn-orphans #-} ======
 +~~DISCUSSION~~
  
   * prevents warnings of orphan instance, meaning:   * prevents warnings of orphan instance, meaning:
     * instance declaration of a type is not declared in the module of the class     * instance declaration of a type is not declared in the module of the class
 +  * NOTE: Orphan instances may be useful.
 +    * see also [[https://wiki.haskell.org/Orphan_instance|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: [[codesnippets:datastructuresfromsymboltrees|Creating data structures from symbol trees]]
   * example:   * example:
     * code of module Lib:<code Haskell>     * code of module Lib:<code Haskell>
Line 35: Line 40:
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
 </code> </code>
 +  * example, with GHC option:
 +    * code:<code Haskell>
 +{-# OPTIONS_GHC -fno-warn-orphans #-}
  
 +import Lib (MyClass(..))
 +
 +main :: IO ()
 +main = print x1
 +
 +instance MyClass Double where
 +    fMy x = (x * x) + x + 1
 +
 +x1 :: Double
 +x1 = fMy 3.4 
 +</code>
 +    * compiles, error and warning free, with compiler: GHC 8.10.4, using compiler option -Wall
 +    * executes, with output:<code>
 +15.959999999999999
 +</code>
 +
 +
 +===== ✎ =====
 +~~DISCUSSION~~
codesnippets/fnowarnorphans.1618080312.txt.gz · Last modified: (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki