Re: [Haskell-cafe] Is it possible to get the information of instances of a type?

2011-11-07 Thread Dmitry Olshansky
For TH look also at
http://www.mail-archive.com/haskell-cafe@haskell.org/msg13057.html


2011/10/27 Magicloud Magiclouds 

> On Thu, Oct 27, 2011 at 1:57 AM, Brent Yorgey 
> wrote:
> > On Wed, Oct 26, 2011 at 09:10:23PM +0400, MigMit wrote:
> >> Can't be done. Even if this particular module doesn't contain
> >> "instance Class Type", it's quite possible that the said instance
> >> would be defined in another module, about which this one knows
> >> nothing about.
> >
> > That doesn't mean it can't be done, only that you would have to be
> > explicit about which modules to look in.
> >
> > -Brent
> >
> > ___
> > Haskell-Cafe mailing list
> > Haskell-Cafe@haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
>
> May I know more about this? Have not used TH on this subject.
>
> --
> 竹密岂妨流水过
> 山高哪阻野云飞
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Is it possible to get the information of instances of a type?

2011-10-26 Thread Magicloud Magiclouds
On Thu, Oct 27, 2011 at 1:57 AM, Brent Yorgey  wrote:
> On Wed, Oct 26, 2011 at 09:10:23PM +0400, MigMit wrote:
>> Can't be done. Even if this particular module doesn't contain
>> "instance Class Type", it's quite possible that the said instance
>> would be defined in another module, about which this one knows
>> nothing about.
>
> That doesn't mean it can't be done, only that you would have to be
> explicit about which modules to look in.
>
> -Brent
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

May I know more about this? Have not used TH on this subject.

-- 
竹密岂妨流水过
山高哪阻野云飞

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Is it possible to get the information of instances of a type?

2011-10-26 Thread Magicloud Magiclouds
On Thu, Oct 27, 2011 at 7:04 AM, Evan Laforge  wrote:
>> No, this lists all the instances of a class.  OP asked for the classes
>> of which a given type is an instace.
>>
>> Presumably it is possible, since Haddock does it!  In the
>> documentation generated for a type it lists classes of which the type
>> is an instance.  So you might want to look at how Haddock does it.  I
>> suspect the only way is through the GHC API.
>
> ghci :info does it too.
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

Generally looked into GHC's source, seems like the :info (line 850 of
compiler/main/InteractiveEval.hs) is internal function. At last, GHC
parsed the code, it sure knew the type info.

-- 
竹密岂妨流水过
山高哪阻野云飞

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Is it possible to get the information of instances of a type?

2011-10-26 Thread Evan Laforge
> No, this lists all the instances of a class.  OP asked for the classes
> of which a given type is an instace.
>
> Presumably it is possible, since Haddock does it!  In the
> documentation generated for a type it lists classes of which the type
> is an instance.  So you might want to look at how Haddock does it.  I
> suspect the only way is through the GHC API.

ghci :info does it too.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Is it possible to get the information of instances of a type?

2011-10-26 Thread Brent Yorgey
On Wed, Oct 26, 2011 at 09:10:23PM +0400, MigMit wrote:
> Can't be done. Even if this particular module doesn't contain
> "instance Class Type", it's quite possible that the said instance
> would be defined in another module, about which this one knows
> nothing about.

That doesn't mean it can't be done, only that you would have to be
explicit about which modules to look in.

-Brent

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Is it possible to get the information of instances of a type?

2011-10-26 Thread Brent Yorgey
On Wed, Oct 26, 2011 at 09:15:41AM -0700, Nathan Howell wrote:
> On Wed, Oct 26, 2011 at 6:53 AM, Magicloud Magiclouds <
> magicloud.magiclo...@gmail.com> wrote:
> 
> >  But in Haskell, could I write a code to list the classes that a type
> > instanced?
> >  TemplateHaskell as well.
> >
> 
> It's possible with TemplateHaskell. Look at classInstances and the ClassI
> data constructor.
> 
> http://haskell.org/ghc/docs/7.0.4/html/libraries/template-haskell-2.5.0.0/Language-Haskell-TH.html#v:classInstances

No, this lists all the instances of a class.  OP asked for the classes
of which a given type is an instace.

Presumably it is possible, since Haddock does it!  In the
documentation generated for a type it lists classes of which the type
is an instance.  So you might want to look at how Haddock does it.  I
suspect the only way is through the GHC API.

-Brent

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Is it possible to get the information of instances of a type?

2011-10-26 Thread MigMit
Can't be done. Even if this particular module doesn't contain "instance Class 
Type", it's quite possible that the said instance would be defined in another 
module, about which this one knows nothing about.

On the other hand, what would you do with that information?

Отправлено с iPad

26.10.2011, в 17:53, Magicloud Magiclouds  
написал(а):

> Hi,
>  If this was in ruby or other languages that support reflection, it
> won't be a question.
>  But in Haskell, could I write a code to list the classes that a type
> instanced?
>  TemplateHaskell as well.
> -- 
> 竹密岂妨流水过
> 山高哪阻野云飞
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Is it possible to get the information of instances of a type?

2011-10-26 Thread Nathan Howell
On Wed, Oct 26, 2011 at 6:53 AM, Magicloud Magiclouds <
magicloud.magiclo...@gmail.com> wrote:

>  But in Haskell, could I write a code to list the classes that a type
> instanced?
>  TemplateHaskell as well.
>

It's possible with TemplateHaskell. Look at classInstances and the ClassI
data constructor.

http://haskell.org/ghc/docs/7.0.4/html/libraries/template-haskell-2.5.0.0/Language-Haskell-TH.html#v:classInstances
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Is it possible to get the information of instances of a type?

2011-10-26 Thread Ertugrul Soeylemez
Magicloud Magiclouds  wrote:

>   If this was in ruby or other languages that support reflection, it
> won't be a question.
>   But in Haskell, could I write a code to list the classes that a type
> instanced?

In regular Haskell, type information is completely lost after
compilation, so you can't recover any of that.  There is no run-time
type information like in languages with OO inheritance.

However, types can choose to provide type information through the
Typeable type class (Data.Typeable).  Generally you wouldn't want to use
it, if you write Haskell properly (i.e. if you don't try to write Ruby
in Haskell).


>   TemplateHaskell as well.

I'm not sure about that one.


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Is it possible to get the information of instances of a type?

2011-10-26 Thread Magicloud Magiclouds
Hi,
  If this was in ruby or other languages that support reflection, it
won't be a question.
  But in Haskell, could I write a code to list the classes that a type
instanced?
  TemplateHaskell as well.
-- 
竹密岂妨流水过
山高哪阻野云飞

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe