
On 11/2/06, Sebastian Sylvan
On 11/2/06, Slavomir Kaslev
wrote: Little by little, I think I am getting closer.
class Show a => Visible a where toString :: a -> String toString = show size :: a -> Int size = length . show
Is just declaration, not definition. It doesn't define anything, even though it has default implementations for toString and size one still needs to define instance of it. Right?
As Sebastian Sylvan proposed, I probably need something like this:
class Visible a where toString :: a -> String size :: a -> Int
instance Show a => Visible a where toString = show size = length . show
But it seems ghc doesn't like instance definitions like 'instance Show a => Visible a where ...'. Why?
This is not Haskell98 since instance declarations of this form could cause the type checker to go into an infinite loop. This particular one is okay, though, but you have to start ghc with -fallow-undecidable-instances and -fglasgow-exts I'm afraid.
-- Sebastian Sylvan +46(0)736-818655 UIN: 44640862
Thanks, Sebastian. That was helpful. Are there any papers on the subject? -- Slavomir Kaslev

On 11/2/06, Slavomir Kaslev
On 11/2/06, Sebastian Sylvan
wrote: On 11/2/06, Slavomir Kaslev
wrote: Little by little, I think I am getting closer.
class Show a => Visible a where toString :: a -> String toString = show size :: a -> Int size = length . show
Is just declaration, not definition. It doesn't define anything, even though it has default implementations for toString and size one still needs to define instance of it. Right?
As Sebastian Sylvan proposed, I probably need something like this:
class Visible a where toString :: a -> String size :: a -> Int
instance Show a => Visible a where toString = show size = length . show
But it seems ghc doesn't like instance definitions like 'instance Show a => Visible a where ...'. Why?
This is not Haskell98 since instance declarations of this form could cause the type checker to go into an infinite loop. This particular one is okay, though, but you have to start ghc with -fallow-undecidable-instances and -fglasgow-exts I'm afraid.
-- Sebastian Sylvan +46(0)736-818655 UIN: 44640862
Thanks, Sebastian. That was helpful. Are there any papers on the subject?
The users guid to GHC explains it quite clearly, in my opinion, though I'm sure there are some papers on the subject as well (I can't think of any right now, though). /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862

Hello Slavomir, Thursday, November 2, 2006, 9:59:38 PM, you wrote:
one is okay, though, but you have to start ghc with -fallow-undecidable-instances and -fglasgow-exts I'm afraid.
Thanks, Sebastian. That was helpful. Are there any papers on the subject?
i recommend you to read in the following sequence: 1) The paper that at first time introduced type classes and their implementation using dictionaries was Philip Wadler and Stephen Blott "How to make ad-hoc polymorphism less ad-hoc" (http://homepages.inf.ed.ac.uk/wadler/papers/class/class.ps.gz) 2) http://haskell.org/haskellwiki/OOP_vs_type_classes 3) Ralf Lammel and Klaus Ostermann paper "Software Extension and Integration with Type Classes" (http://homepages.cwi.nl/~ralf/gpce06/) which prompts me to start thinking about differences between OOP and type classes instead of their similarities 4) ghc user's guide, chapter 7 describes Haskell language extensions 5) You can find more papers on the http://haskell.org/haskellwiki/Research_papers/Type_systems#Type_classes page. Of those papers i found a most interesting "exporing the design space" one 6) The best paper on type level arithmetic using type classes i've seen is "Faking it: simulating dependent types in Haskell" ( http://www.cs.nott.ac.uk/~ctm/faking.ps.gz ) 7) The great demonstration of type-level arithmetic is TypeNats package which "defines type-level natural numbers and arithmetic operations on them including addition, subtraction, multiplication, division and GCD" ( darcs get --partial --tag '0.1' http://www.eecs.tufts.edu/~rdocki01/typenats/ ) 8) I should also mention here Oleg Kiselyov page on class-based type-level programming in Haskell: http://okmij.org/ftp/Haskell/types.html -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

On 11/3/06, Bulat Ziganshin
Hello Slavomir,
Thursday, November 2, 2006, 9:59:38 PM, you wrote:
one is okay, though, but you have to start ghc with -fallow-undecidable-instances and -fglasgow-exts I'm afraid.
Thanks, Sebastian. That was helpful. Are there any papers on the subject?
i recommend you to read in the following sequence:
1) The paper that at first time introduced type classes and their implementation using dictionaries was Philip Wadler and Stephen Blott "How to make ad-hoc polymorphism less ad-hoc" (http://homepages.inf.ed.ac.uk/wadler/papers/class/class.ps.gz)
2) http://haskell.org/haskellwiki/OOP_vs_type_classes
3) Ralf Lammel and Klaus Ostermann paper "Software Extension and Integration with Type Classes" (http://homepages.cwi.nl/~ralf/gpce06/) which prompts me to start thinking about differences between OOP and type classes instead of their similarities
4) ghc user's guide, chapter 7 describes Haskell language extensions
5) You can find more papers on the http://haskell.org/haskellwiki/Research_papers/Type_systems#Type_classes page. Of those papers i found a most interesting "exporing the design space" one
6) The best paper on type level arithmetic using type classes i've seen is "Faking it: simulating dependent types in Haskell" ( http://www.cs.nott.ac.uk/~ctm/faking.ps.gz )
7) The great demonstration of type-level arithmetic is TypeNats package which "defines type-level natural numbers and arithmetic operations on them including addition, subtraction, multiplication, division and GCD" ( darcs get --partial --tag '0.1' http://www.eecs.tufts.edu/~rdocki01/typenats/ )
8) I should also mention here Oleg Kiselyov page on class-based type-level programming in Haskell: http://okmij.org/ftp/Haskell/types.html
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
Wow. Thank you for the comprehensive list. I feel almost obligated reading =-) Cheers. -- Slavomir Kaslev
participants (3)
-
Bulat Ziganshin
-
Sebastian Sylvan
-
Slavomir Kaslev