Re: [Haskell-cafe] some ideas for Haskell', from Python

Artyom Shalkhakov ha scritto:
Hi Manlio,
Hi Artyom. Note that it seems you have sent this message only to me; I'm sending the reply to both you and the mailing list.
2009/1/14 Manlio Perillo
: 2) In Python it is possible to import modules inside a function.
In Haskell something like:
joinPath' root name = joinPath [root, name] importing System.FilePath (joinPath)
I guess you're talking about first-class modules, the ones that might be passed to functions as arguments, returned from functions as a result, loaded at run-time, etc.
No, I was not going that far :). I simply was proposing a method to keep imported definitions local to a function. By the way, here is a strange (for me) problem I hit, and made me think about this extension. Suppose a file foo.hs defines: import Control.Monad import System.Posix.Files as PF isDirectory :: FilePath -> IO Bool isDirectory path = PF.isDirectory `liftM` PF.getFileStatus path If I try to load the file from ghci I get: Prelude> :l foo.hs [1 of 1] Compiling Main ( foo.hs, interpreted ) Ok, modules loaded: Main. *Main> isDirectory "/var" <interactive>:1:0: Ambiguous occurrence `isDirectory' It could refer to either `Main.isDirectory', defined at foo.hs:6:0 or `PF.isDirectory', imported from System.Posix.Files at foo.hs:2:0-30
[...]
Manlio Perillo

Gleb Alexeyev ha scritto:
Manlio Perillo wrote:
import System.Posix.Files as PF
Try this:
import qualified System.Posix.Files as PF
The problem you described should go away.
Ah, thanks! I really missed the qualified! Manlio Perillo

Hi Manlio
2009/1/15 Manlio Perillo
Note that it seems you have sent this message only to me; I'm sending the reply to both you and the mailing list.
Yes, sorry, I always forget forwading to the mailing list. :(
By the way, here is a strange (for me) problem I hit, and made me think about this extension.
Suppose a file foo.hs defines:
import Control.Monad import System.Posix.Files as PF
isDirectory :: FilePath -> IO Bool isDirectory path = PF.isDirectory `liftM` PF.getFileStatus path
If I try to load the file from ghci I get:
Prelude> :l foo.hs [1 of 1] Compiling Main ( foo.hs, interpreted ) Ok, modules loaded: Main. *Main> isDirectory "/var"
<interactive>:1:0: Ambiguous occurrence `isDirectory' It could refer to either `Main.isDirectory', defined at foo.hs:6:0 or `PF.isDirectory', imported from System.Posix.Files at foo.hs:2:0-30
That's exactly the problem of "function call hi-jacking". [1] In Haskell it's solved using qualified imports. Cheers, Artyom Shalkhakov. [1] http://digitalmars.com/d/2.0/hijack.html

Artyom Shalkhakov ha scritto:
[...]
Prelude> :l foo.hs [1 of 1] Compiling Main ( foo.hs, interpreted ) Ok, modules loaded: Main. *Main> isDirectory "/var"
<interactive>:1:0: Ambiguous occurrence `isDirectory' It could refer to either `Main.isDirectory', defined at foo.hs:6:0 or `PF.isDirectory', imported from System.Posix.Files at foo.hs:2:0-30
That's exactly the problem of "function call hi-jacking". [1] In Haskell it's solved using qualified imports.
What a surprise to see there are others that know both Haskell and D ;-). I find D a very interesting language. I also have support for pure functions. Regards Manlio Perillo
participants (3)
-
Artyom Shalkhakov
-
Gleb Alexeyev
-
Manlio Perillo