Type constructor

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Type constructor

Mike Houghton
Hi,

I’m modelling fractions with a view to looking at continued fractions and I have this recursive structure.

type Numerator   = Integer
data Fraction = Numbr Integer | F Numerator Fraction


in ghci I do

λ-> :t F 1 (Numbr 2)
F 1 (Numbr 2) :: Fraction

which is fine. But what surprised me is that it also works without using Numbr e.g.

λ-> :t F 1 2
F 1 2 :: Fraction

why is this?

Thanks

Mike
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Type constructor

David McBride
The only thing I can think of is that you wrote a Num instance for Fraction.  That allows it to represent a fraction as a literal 2 because you can create a fraction from an integer via fromInteger.

On Wed, Nov 8, 2017 at 2:21 PM, mike h <[hidden email]> wrote:
Hi,

I’m modelling fractions with a view to looking at continued fractions and I have this recursive structure.

type Numerator   = Integer
data Fraction = Numbr Integer | F Numerator Fraction


in ghci I do

λ-> :t F 1 (Numbr 2)
F 1 (Numbr 2) :: Fraction

which is fine. But what surprised me is that it also works without using Numbr e.g.

λ-> :t F 1 2
F 1 2 :: Fraction

why is this?

Thanks

Mike
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Type constructor

Mike Houghton
Duh!   
Give that man a ceeeegar! 
Thanks
:)

On 8 Nov 2017, at 19:31, David McBride <[hidden email]> wrote:

The only thing I can think of is that you wrote a Num instance for Fraction.  That allows it to represent a fraction as a literal 2 because you can create a fraction from an integer via fromInteger.

On Wed, Nov 8, 2017 at 2:21 PM, mike h <[hidden email]> wrote:
Hi,

I’m modelling fractions with a view to looking at continued fractions and I have this recursive structure.

type Numerator   = Integer
data Fraction = Numbr Integer | F Numerator Fraction


in ghci I do

λ-> :t F 1 (Numbr 2)
F 1 (Numbr 2) :: Fraction

which is fine. But what surprised me is that it also works without using Numbr e.g.

λ-> :t F 1 2
F 1 2 :: Fraction

why is this?

Thanks

Mike
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners