Hi,
these days I'm thinking about name scoping in Haskell and a question
built up silently but steadily in my mind.
Many times I see code like this:
data Foo = { fooBar :: Int, fooSay :: String, fooClose :: String }
which reminds me of "Ye Olde Times" of C where you prepend the
structure name (
Hello Cristiano,
Wednesday, January 13, 2010, 9:43:06 PM, you wrote:
> coming up to my mind is that type inference actually forbids a
> type-directed resolution of names as in C++ or Java.
you are right. we either have ad-hoc polymorphism like in C++ where
type of id selected based on type of ar
The usual suggestion I see for this sort of thing is to create a
typeclass for the operations you care about[1][2]. For example:
---
class HasOpen a where
open :: a -> Handle
data DB
data FS
openDB :: DB ->
Well, you can get part of the way there, by using a class associated type
class HasOpen a where
type Open a :: *
open :: a -> Open a
This lets you use type inference in one direction, without requiring that
every result be a member of a data family. On the other hand, type inference
just be
> Now, in Haskell we have type inference, which is "The Good Thing" as
> it allows to "validate" your program at compile time. Hence, the idea
> coming up to my mind is that type inference actually forbids a
> type-directed resolution of names as in C++ or Java.
>
> Is this correct?
There is a pro
I wish to thank all of you for your comments.
In fact, the solutions you proposed mostly coincided with mine
(including the one using type families) but, in my opinion, they are
more cumbersome than the prefixed names solution.
Going back to my example:
f x = open $ open x
where:
data Foo = {
Hello John,
Wednesday, January 13, 2010, 10:08:08 PM, you wrote:
> Of course, this doesn't allow you to have functions share the same
> name if they have different signatures
class Open a where
open :: a
instance Open (Int -> String) where ...
instance Open (String -> Int) where ...
--
Best
>
> On Wed, Jan 13, 2010 at 2:14 PM, Bulat Ziganshin <
> bulat.zigans...@gmail.com> wrote:
>
> class Open a where
> open :: a
>
> instance Open (Int -> String) where ...
> instance Open (String -> Int) where ...
>
The problem with this approach is that you'll need to supply type
annotations with