codesnippets:avoidconflictprelude
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| codesnippets:avoidconflictprelude [2021/04/10 13:50] – f2b216 | codesnippets:avoidconflictprelude [2025/10/08 00:48] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Avoiding name conflict with Prelude ====== | ====== Avoiding name conflict with Prelude ====== | ||
| - | ~~DISCUSSION~~ | ||
| The avoidance of prelude may make sense for the following reasons: | The avoidance of prelude may make sense for the following reasons: | ||
| Line 8: | Line 7: | ||
| Methods: | Methods: | ||
| + | * Hide functions from prelude. | ||
| * The directive '' | * The directive '' | ||
| * If you import '' | * If you import '' | ||
| 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 " | ||
| + | |||
| + | |||
| + | reverse :: [a] -> [a] | ||
| + | reverse l = rev l [] | ||
| + | where | ||
| + | rev [] acc = acc | ||
| + | rev (e:r) acc = rev r (e : acc) | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Example #2 ===== | ||
| Qualified import of preload overrides implicit import. | Qualified import of preload overrides implicit import. | ||
| Line 41: | Line 63: | ||
| </ | </ | ||
| - | ===== Example #2 ===== | + | ===== Example #3 ===== |
| The same with directive '' | The same with directive '' | ||
| Line 69: | Line 91: | ||
| </ | </ | ||
| - | ===== Example #3 ===== | + | ===== Example #4 ===== |
| With import of all functions that are needed only. | With import of all functions that are needed only. | ||
| Line 95: | Line 117: | ||
| </ | </ | ||
| - | ===== Example #4 ===== | + | ===== Example #5 ===== |
| Shows what happens without measures, like the above. | Shows what happens without measures, like the above. | ||
| Line 127: | Line 149: | ||
| </ | </ | ||
| - | ===== Example #5 ===== | + | ===== Example #6 ===== |
| Shows what happens with directive '' | Shows what happens with directive '' | ||
| Line 158: | Line 180: | ||
| + | ===== ✎ ===== | ||
| + | ~~DISCUSSION~~ | ||
codesnippets/avoidconflictprelude.1618055445.txt.gz · Last modified: (external edit)
