Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Prelude with hiding, how to undo?

In one file I need to use the regular prelude (++) operator and I also wish to implement my own behaviour for (++). I have used import Prelude hiding (++) at the top of my file, defined my own (++) operator and now further below I wish to refer to the regular Prelude's (++). How do I achieve this?

like image 483
user997112 Avatar asked Nov 06 '11 22:11

user997112


2 Answers

Write

import qualified Prelude

in addition to

import Prelude hiding ((++))

at the beginning of the code, and write Prelude.++ where you need ++ in Prelude.

like image 75
Tsuyoshi Ito Avatar answered Sep 28 '22 07:09

Tsuyoshi Ito


As Tsuyoshi Ito explained, you can qualify the operator by its module name. However, since by defining your own version of (++) you most likely want to increase the readabilty of your program, qualifying an operator with its module name later on seems to be a weird measure.

Just look at this: "abc" Prelude.++ "def" Now that's ugly.

Why not simply create a new operator, like <++> or an infix function like `append`?

like image 33
bzn Avatar answered Sep 28 '22 08:09

bzn