codesnippets:avoidconflictprelude

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
codesnippets:avoidconflictprelude [2022/10/05 14:21] – external edit codesnippets:avoidconflictprelude [2025/10/08 00:48] (current) – external edit 127.0.0.1
Line 1: Line 1:
-~~DISCUSSION~~ 
 ====== Avoiding name conflict with Prelude ====== ====== Avoiding name conflict with Prelude ======
  
Line 8: Line 7:
  
 Methods: Methods:
 +  * Hide functions from prelude.
   * The directive ''{-# LANGUAGE NoImplicitPrelude #-}'' can be used to avoid implicit import of module ''Prelude''   * The directive ''{-# LANGUAGE NoImplicitPrelude #-}'' can be used to avoid implicit import of module ''Prelude''
   * If you import ''Prelude'' by ''import qualified Prelude as <Prefix>'' then the directive above is not neccessary, because Prelude will only be imported qualified. However, the directive above will not harm.   * If you import ''Prelude'' by ''import qualified Prelude as <Prefix>'' then the directive above is not neccessary, because Prelude will only be imported qualified. However, the directive above will not harm.
Line 15: Line 15:
  
 ===== Example #1 ===== ===== Example #1 =====
 +
 +Hide functions from prelude.
 +
 +<code Haskell>
 +module Main where
 +
 +import Prelude hiding( reverse )
 +
 +main :: IO ()
 +main = do
 +    putStrLn $ reverse "1234abcd"
 +
 +
 +reverse :: [a] -> [a]
 +reverse l = rev l []
 +    where
 +        rev [] acc = acc
 +        rev (e:r) acc = rev r (e : acc)
 +</code>
 +
 +
 +===== Example #2 =====
  
 Qualified import of preload overrides implicit import. Qualified import of preload overrides implicit import.
Line 41: Line 63:
 </code> </code>
  
-===== Example #=====+===== Example #=====
  
 The same with directive ''{-# LANGUAGE NoImplicitPrelude #-}''. The same with directive ''{-# LANGUAGE NoImplicitPrelude #-}''.
Line 69: Line 91:
 </code> </code>
  
-===== Example #=====+===== Example #=====
  
 With import of all functions that are needed only. With import of all functions that are needed only.
Line 95: Line 117:
 </code> </code>
  
-===== Example #=====+===== Example #=====
  
 Shows what happens without measures, like the above. Shows what happens without measures, like the above.
Line 127: Line 149:
 </code> </code>
  
-===== Example #=====+===== Example #=====
  
 Shows what happens with directive ''{-# LANGUAGE NoImplicitPrelude #-}'' only. Shows what happens with directive ''{-# LANGUAGE NoImplicitPrelude #-}'' only.
Line 158: Line 180:
  
  
 +===== ✎ =====
 +~~DISCUSSION~~
codesnippets/avoidconflictprelude.1664972506.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