
"Learn You a Haskell ..." says that (->) is a type just like Either. Where can I find its type definition? Michael

2010/8/31 michael rice
"Learn You a Haskell ..." says that (->) is a type just like Either. Where can I find its type definition?
You can't define it *in* Haskell as user code. It is a built-in infix type constructor (Either or Maybe are type constructors too, not just types). In fact, if you want to implement a simple, typed functional language, you'll find it is the only built-in type constructor you have to implement (as the implementor of the language). Also, Show a => a is a type too, but you won't find a definition for 'a' or for '=>'. All those things are defined by the language. Cheers, Thu

So it's a type constructor, not a type? Could you please provide a simple example of its usage?
Michael
--- On Tue, 8/31/10, Vo Minh Thu
"Learn You a Haskell ..." says that (->) is a type just like Either. Where can I find its type definition?
You can't define it *in* Haskell as user code. It is a built-in infix type constructor (Either or Maybe are type constructors too, not just types). In fact, if you want to implement a simple, typed functional language, you'll find it is the only built-in type constructor you have to implement (as the implementor of the language). Also, Show a => a is a type too, but you won't find a definition for 'a' or for '=>'. All those things are defined by the language. Cheers, Thu

Hello michael, Tuesday, August 31, 2010, 9:27:17 PM, you wrote: f :: Int -> Int i.e. it's used when you define function types
So it's a type constructor, not a type? Could you please provide a simple example of its usage?
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote:
From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:17 PM
2010/8/31 michael rice
"Learn You a Haskell ..." says that (->) is a type just like Either. Where can I find its type definition?
You can't define it *in* Haskell as user code. It is a built-in infix type constructor (Either or Maybe are type constructors too, not just types). In fact, if you want to implement a simple, typed functional language, you'll find it is the only built-in type constructor you have to implement (as the implementor of the language).
Also, Show a => a is a type too, but you won't find a definition for 'a' or for '=>'. All those things are defined by the language.
Cheers, Thu
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

2010/8/31 michael rice
So it's a type constructor, not a type? Could you please provide a simple example of its usage?
Sure, although I'm sure you've come by some already. -- the identity function id :: a -> a -- often, we write it like this: -- id x = x -- but here we see the relationship between the ananymous function syntax and the function type: id = \x -> x In fact, if you write in prefix form, it is quite familiar: f :: (->) Int Bool e = Either String Float Cheers, Thu
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:17 PM 2010/8/31 michael rice
"Learn You a Haskell ..." says that (->) is a type just like Either. Where can I find its type definition?
You can't define it *in* Haskell as user code. It is a built-in infix type constructor (Either or Maybe are type constructors too, not just types). In fact, if you want to implement a simple, typed functional language, you'll find it is the only built-in type constructor you have to implement (as the implementor of the language).
Also, Show a => a is a type too, but you won't find a definition for 'a' or for '=>'. All those things are defined by the language.
Cheers, Thu

I'm not sure if my terminology is correct or even if my question makes sense, but I can create "instances" of Maybe, List, IO, and Either.
Prelude Data.Either> let m = Just 7
Prelude Data.Either> :t m
m :: Maybe Integer
Prelude Data.Either> let l = 2:[]
Prelude Data.Either> :t l
l :: [Integer]
Prelude Data.Either> let g = getLine
Prelude Data.Either> :t g
g :: IO String
Prelude Data.Either> let e = Right "abc"
Prelude Data.Either> :t e
e :: Either a [Char]
All these instances are functors, each with its own version of fmap that can be applied to it.
How can I similarly create an instance of (->) so I can apply (->)'s version of fmap
instance Functor ((->) r) where
fmap f g = (\x -> f (g x))
to it?
Michael
--- On Tue, 8/31/10, Vo Minh Thu
So it's a type constructor, not a type? Could you please provide a simple example of its usage?
Sure, although I'm sure you've come by some already. -- the identity function id :: a -> a -- often, we write it like this: -- id x = x -- but here we see the relationship between the ananymous function syntax and the function type: id = \x -> x In fact, if you write in prefix form, it is quite familiar: f :: (->) Int Bool e = Either String Float Cheers, Thu
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:17 PM 2010/8/31 michael rice
"Learn You a Haskell ..." says that (->) is a type just like Either. Where can I find its type definition?
You can't define it *in* Haskell as user code. It is a built-in infix type constructor (Either or Maybe are type constructors too, not just types). In fact, if you want to implement a simple, typed functional language, you'll find it is the only built-in type constructor you have to implement (as the implementor of the language).
Also, Show a => a is a type too, but you won't find a definition for 'a' or for '=>'. All those things are defined by the language.
Cheers, Thu

Prelude FmapFunc> let s = show :: ((->) Int) String
Prelude FmapFunc> :t s
s :: Int -> String
Prelude FmapFunc> let v = fmap ("hello " ++) s
Prelude FmapFunc> :t v
v :: Int -> String
Prelude FmapFunc> v 1
"hello 1"
-- ryan
On Tue, Aug 31, 2010 at 11:28 AM, michael rice
I'm not sure if my terminology is correct or even if my question makes sense, but I can create "instances" of Maybe, List, IO, and Either.
Prelude Data.Either> let m = Just 7 Prelude Data.Either> :t m m :: Maybe Integer
Prelude Data.Either> let l = 2:[] Prelude Data.Either> :t l l :: [Integer]
Prelude Data.Either> let g = getLine Prelude Data.Either> :t g g :: IO String
Prelude Data.Either> let e = Right "abc" Prelude Data.Either> :t e e :: Either a [Char]
All these instances are functors, each with its own version of fmap that can be applied to it.
How can I similarly create an instance of (->) so I can apply (->)'s version of fmap
instance Functor ((->) r) where fmap f g = (\x -> f (g x))
to it?
Michael
--- On *Tue, 8/31/10, Vo Minh Thu
* wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:50 PM 2010/8/31 michael rice
http://mc/compose?to=nowgate@yahoo.com So it's a type constructor, not a type? Could you please provide a simple
example of its usage?
Sure, although I'm sure you've come by some already.
-- the identity function id :: a -> a -- often, we write it like this: -- id x = x -- but here we see the relationship between the ananymous function syntax and the function type: id = \x -> x
In fact, if you write in prefix form, it is quite familiar: f :: (->) Int Bool e = Either String Float
Cheers, Thu
Michael
--- On Tue, 8/31/10, Vo Minh Thu
http://mc/compose?to=noteed@gmail.com> wrote: From: Vo Minh Thu
http://mc/compose?to=noteed@gmail.com Subject: Re: [Haskell-cafe] On to applicative To: "michael rice"
http://mc/compose?to=nowgate@yahoo.com Cc: haskell-cafe@haskell.orghttp://mc/compose?to=haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:17 PM
2010/8/31 michael rice
http://mc/compose?to=nowgate@yahoo.com "Learn You a Haskell ..." says that (->) is a type just like Either.
Where can I find its type definition?
You can't define it *in* Haskell as user code. It is a built-in infix type constructor (Either or Maybe are type constructors too, not just types). In fact, if you want to implement a simple, typed functional language, you'll find it is the only built-in type constructor you have to implement (as the implementor of the language).
Also, Show a => a is a type too, but you won't find a definition for 'a' or for '=>'. All those things are defined by the language.
Cheers, Thu
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi, Ryan and all,
Bingo! I guess my question was all right after all.
I tried creating an instance earlier but
*Main> :t (->) Int Char
<interactive>:1:1: parse error on input `->'
What got loaded with FmapFunc? I Hoogled it and got back nothing.
Michael
--- On Tue, 8/31/10, Ryan Ingram
So it's a type constructor, not a type? Could you please provide a simple example of its usage?
Sure, although I'm sure you've come by some already. -- the identity function id :: a -> a -- often, we write it like this: -- id x = x -- but here we see the relationship between the ananymous function syntax and the function type: id = \x -> x In fact, if you write in prefix form, it is quite familiar: f :: (->) Int Bool e = Either String Float Cheers, Thu
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote:
From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice"
Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:17 PM
2010/8/31 michael rice
"Learn You a Haskell ..." says that (->) is a type just like Either. Where can I find its type definition?
You can't define it *in* Haskell as user code. It is a built-in infix
type constructor (Either or Maybe are type constructors too, not just types). In fact, if you want to implement a simple, typed functional language, you'll find it is the only built-in type constructor you
have to implement (as the implementor of the language).
Also, Show a => a is a type too, but you won't find a definition for 'a' or for '=>'. All those things are defined by the language.
Cheers, Thu
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

2010/8/31 michael rice
Hi, Ryan and all,
Bingo! I guess my question was all right after all.
I tried creating an instance earlier but
*Main> :t (->) Int Char
<interactive>:1:1: parse error on input `->'
:t Int does not make sense but :t undefined :: Int is ok, just like :t undefined :: (->) Int Int
What got loaded with FmapFunc? I Hoogled it and got back nothing.
Michael
--- On Tue, 8/31/10, Ryan Ingram
wrote: From: Ryan Ingram
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: "Vo Minh Thu" , haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 2:36 PM Prelude FmapFunc> let s = show :: ((->) Int) String Prelude FmapFunc> :t s s :: Int -> String Prelude FmapFunc> let v = fmap ("hello " ++) s Prelude FmapFunc> :t v v :: Int -> String Prelude FmapFunc> v 1 "hello 1"
-- ryan
On Tue, Aug 31, 2010 at 11:28 AM, michael rice
wrote: I'm not sure if my terminology is correct or even if my question makes sense, but I can create "instances" of Maybe, List, IO, and Either.
Prelude Data.Either> let m = Just 7 Prelude Data.Either> :t m m :: Maybe Integer
Prelude Data.Either> let l = 2:[] Prelude Data.Either> :t l l :: [Integer]
Prelude Data.Either> let g = getLine Prelude Data.Either> :t g g :: IO String
Prelude Data.Either> let e = Right "abc" Prelude Data.Either> :t e e :: Either a [Char]
All these instances are functors, each with its own version of fmap that can be applied to it.
How can I similarly create an instance of (->) so I can apply (->)'s version of fmap
instance Functor ((->) r) where fmap f g = (\x -> f (g x))
to it?
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:50 PM 2010/8/31 michael rice
So it's a type constructor, not a type? Could you please provide a simple example of its usage?
Sure, although I'm sure you've come by some already.
-- the identity function id :: a -> a -- often, we write it like this: -- id x = x -- but here we see the relationship between the ananymous function syntax and the function type: id = \x -> x
In fact, if you write in prefix form, it is quite familiar: f :: (->) Int Bool e = Either String Float
Cheers, Thu
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:17 PM 2010/8/31 michael rice
"Learn You a Haskell ..." says that (->) is a type just like Either. Where can I find its type definition?
You can't define it *in* Haskell as user code. It is a built-in infix type constructor (Either or Maybe are type constructors too, not just types). In fact, if you want to implement a simple, typed functional language, you'll find it is the only built-in type constructor you have to implement (as the implementor of the language).
Also, Show a => a is a type too, but you won't find a definition for 'a' or for '=>'. All those things are defined by the language.
Cheers, Thu
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi Vo,
Pardon, I grabbed the wrong lines.
*Main> :t (->) 3 "abc"
<interactive>:1:1: parse error on input `->'
Michael
--- On Tue, 8/31/10, Vo Minh Thu
Hi, Ryan and all,
Bingo! I guess my question was all right after all.
I tried creating an instance earlier but
*Main> :t (->) Int Char
<interactive>:1:1: parse error on input `->'
:t Int does not make sense but :t undefined :: Int is ok, just like :t undefined :: (->) Int Int
What got loaded with FmapFunc? I Hoogled it and got back nothing.
Michael
--- On Tue, 8/31/10, Ryan Ingram
wrote: From: Ryan Ingram
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: "Vo Minh Thu" , haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 2:36 PM Prelude FmapFunc> let s = show :: ((->) Int) String Prelude FmapFunc> :t s s :: Int -> String Prelude FmapFunc> let v = fmap ("hello " ++) s Prelude FmapFunc> :t v v :: Int -> String Prelude FmapFunc> v 1 "hello 1"
-- ryan
On Tue, Aug 31, 2010 at 11:28 AM, michael rice
wrote: I'm not sure if my terminology is correct or even if my question makes sense, but I can create "instances" of Maybe, List, IO, and Either.
Prelude Data.Either> let m = Just 7 Prelude Data.Either> :t m m :: Maybe Integer
Prelude Data.Either> let l = 2:[] Prelude Data.Either> :t l l :: [Integer]
Prelude Data.Either> let g = getLine Prelude Data.Either> :t g g :: IO String
Prelude Data.Either> let e = Right "abc" Prelude Data.Either> :t e e :: Either a [Char]
All these instances are functors, each with its own version of fmap that can be applied to it.
How can I similarly create an instance of (->) so I can apply (->)'s version of fmap
instance Functor ((->) r) where fmap f g = (\x -> f (g x))
to it?
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:50 PM 2010/8/31 michael rice
So it's a type constructor, not a type? Could you please provide a simple example of its usage?
Sure, although I'm sure you've come by some already.
-- the identity function id :: a -> a -- often, we write it like this: -- id x = x -- but here we see the relationship between the ananymous function syntax and the function type: id = \x -> x
In fact, if you write in prefix form, it is quite familiar: f :: (->) Int Bool e = Either String Float
Cheers, Thu
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:17 PM 2010/8/31 michael rice
"Learn You a Haskell ..." says that (->) is a type just like Either. Where can I find its type definition?
You can't define it *in* Haskell as user code. It is a built-in infix type constructor (Either or Maybe are type constructors too, not just types). In fact, if you want to implement a simple, typed functional language, you'll find it is the only built-in type constructor you have to implement (as the implementor of the language).
Also, Show a => a is a type too, but you won't find a definition for 'a' or for '=>'. All those things are defined by the language.
Cheers, Thu
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

2010/8/31 michael rice
Hi Vo,
Pardon, I grabbed the wrong lines.
*Main> :t (->) 3 "abc"
<interactive>:1:1: parse error on input `->'
Try *Main> :t undefined :: (->) 3 "abc" You can't write :t <some type> You have to write :t <some value>
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: "Ryan Ingram" , haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 3:07 PM 2010/8/31 michael rice
Hi, Ryan and all,
Bingo! I guess my question was all right after all.
I tried creating an instance earlier but
*Main> :t (->) Int Char
<interactive>:1:1: parse error on input `->'
:t Int does not make sense but :t undefined :: Int is ok, just like :t undefined :: (->) Int Int
What got loaded with FmapFunc? I Hoogled it and got back nothing.
Michael
--- On Tue, 8/31/10, Ryan Ingram
wrote: From: Ryan Ingram
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: "Vo Minh Thu" , haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 2:36 PM Prelude FmapFunc> let s = show :: ((->) Int) String Prelude FmapFunc> :t s s :: Int -> String Prelude FmapFunc> let v = fmap ("hello " ++) s Prelude FmapFunc> :t v v :: Int -> String Prelude FmapFunc> v 1 "hello 1"
-- ryan
On Tue, Aug 31, 2010 at 11:28 AM, michael rice
wrote: I'm not sure if my terminology is correct or even if my question makes sense, but I can create "instances" of Maybe, List, IO, and Either.
Prelude Data.Either> let m = Just 7 Prelude Data.Either> :t m m :: Maybe Integer
Prelude Data.Either> let l = 2:[] Prelude Data.Either> :t l l :: [Integer]
Prelude Data.Either> let g = getLine Prelude Data.Either> :t g g :: IO String
Prelude Data.Either> let e = Right "abc" Prelude Data.Either> :t e e :: Either a [Char]
All these instances are functors, each with its own version of fmap that can be applied to it.
How can I similarly create an instance of (->) so I can apply (->)'s version of fmap
instance Functor ((->) r) where fmap f g = (\x -> f (g x))
to it?
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:50 PM 2010/8/31 michael rice
So it's a type constructor, not a type? Could you please provide a simple example of its usage?
Sure, although I'm sure you've come by some already.
-- the identity function id :: a -> a -- often, we write it like this: -- id x = x -- but here we see the relationship between the ananymous function syntax and the function type: id = \x -> x
In fact, if you write in prefix form, it is quite familiar: f :: (->) Int Bool e = Either String Float
Cheers, Thu
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:17 PM 2010/8/31 michael rice
"Learn You a Haskell ..." says that (->) is a type just like Either. Where can I find its type definition?
You can't define it *in* Haskell as user code. It is a built-in infix type constructor (Either or Maybe are type constructors too, not just types). In fact, if you want to implement a simple, typed functional language, you'll find it is the only built-in type constructor you have to implement (as the implementor of the language).
Also, Show a => a is a type too, but you won't find a definition for 'a' or for '=>'. All those things are defined by the language.
Cheers, Thu
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

You most certainly meant
Prelude Data.Either> :t undefined :: (->) Int String
undefined :: (->) Int String :: Int -> String
though it is confusing. Constructors usually take values, but here the values (->) takes are types.
Michael
--- On Tue, 8/31/10, Vo Minh Thu
Hi Vo,
Pardon, I grabbed the wrong lines.
*Main> :t (->) 3 "abc"
<interactive>:1:1: parse error on input `->'
Try *Main> :t undefined :: (->) 3 "abc" You can't write :t <some type> You have to write :t <some value>
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: "Ryan Ingram" , haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 3:07 PM 2010/8/31 michael rice
Hi, Ryan and all,
Bingo! I guess my question was all right after all.
I tried creating an instance earlier but
*Main> :t (->) Int Char
<interactive>:1:1: parse error on input `->'
:t Int does not make sense but :t undefined :: Int is ok, just like :t undefined :: (->) Int Int
What got loaded with FmapFunc? I Hoogled it and got back nothing.
Michael
--- On Tue, 8/31/10, Ryan Ingram
wrote: From: Ryan Ingram
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: "Vo Minh Thu" , haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 2:36 PM Prelude FmapFunc> let s = show :: ((->) Int) String Prelude FmapFunc> :t s s :: Int -> String Prelude FmapFunc> let v = fmap ("hello " ++) s Prelude FmapFunc> :t v v :: Int -> String Prelude FmapFunc> v 1 "hello 1"
-- ryan
On Tue, Aug 31, 2010 at 11:28 AM, michael rice
wrote: I'm not sure if my terminology is correct or even if my question makes sense, but I can create "instances" of Maybe, List, IO, and Either.
Prelude Data.Either> let m = Just 7 Prelude Data.Either> :t m m :: Maybe Integer
Prelude Data.Either> let l = 2:[] Prelude Data.Either> :t l l :: [Integer]
Prelude Data.Either> let g = getLine Prelude Data.Either> :t g g :: IO String
Prelude Data.Either> let e = Right "abc" Prelude Data.Either> :t e e :: Either a [Char]
All these instances are functors, each with its own version of fmap that can be applied to it.
How can I similarly create an instance of (->) so I can apply (->)'s version of fmap
instance Functor ((->) r) where fmap f g = (\x -> f (g x))
to it?
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:50 PM 2010/8/31 michael rice
So it's a type constructor, not a type? Could you please provide a simple example of its usage?
Sure, although I'm sure you've come by some already.
-- the identity function id :: a -> a -- often, we write it like this: -- id x = x -- but here we see the relationship between the ananymous function syntax and the function type: id = \x -> x
In fact, if you write in prefix form, it is quite familiar: f :: (->) Int Bool e = Either String Float
Cheers, Thu
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:17 PM 2010/8/31 michael rice
"Learn You a Haskell ..." says that (->) is a type just like Either. Where can I find its type definition?
You can't define it *in* Haskell as user code. It is a built-in infix type constructor (Either or Maybe are type constructors too, not just types). In fact, if you want to implement a simple, typed functional language, you'll find it is the only built-in type constructor you have to implement (as the implementor of the language).
Also, Show a => a is a type too, but you won't find a definition for 'a' or for '=>'. All those things are defined by the language.
Cheers, Thu
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

2010/8/31 michael rice
You most certainly meant
Prelude Data.Either> :t undefined :: (->) Int String undefined :: (->) Int String :: Int -> String
though it is confusing. Constructors usually take values, but here the values (->) takes are types.
Either and (->) are *type* constructors. Just is a (value) constructor. This makes sense: Just 7 is a value, so Just surely constructs a value. Nothing doesn't take an argument but is called a constructor too. Maybe Int is a type, so Maybe surely constructs a type.
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: "Ryan Ingram" , haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 3:23 PM 2010/8/31 michael rice
Hi Vo,
Pardon, I grabbed the wrong lines.
*Main> :t (->) 3 "abc"
<interactive>:1:1: parse error on input `->'
Try
*Main> :t undefined :: (->) 3 "abc"
You can't write :t <some type> You have to write :t <some value>
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: "Ryan Ingram" , haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 3:07 PM 2010/8/31 michael rice
Hi, Ryan and all,
Bingo! I guess my question was all right after all.
I tried creating an instance earlier but
*Main> :t (->) Int Char
<interactive>:1:1: parse error on input `->'
:t Int does not make sense but :t undefined :: Int is ok, just like :t undefined :: (->) Int Int
What got loaded with FmapFunc? I Hoogled it and got back nothing.
Michael
--- On Tue, 8/31/10, Ryan Ingram
wrote: From: Ryan Ingram
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: "Vo Minh Thu" , haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 2:36 PM Prelude FmapFunc> let s = show :: ((->) Int) String Prelude FmapFunc> :t s s :: Int -> String Prelude FmapFunc> let v = fmap ("hello " ++) s Prelude FmapFunc> :t v v :: Int -> String Prelude FmapFunc> v 1 "hello 1"
-- ryan
On Tue, Aug 31, 2010 at 11:28 AM, michael rice
wrote: I'm not sure if my terminology is correct or even if my question makes sense, but I can create "instances" of Maybe, List, IO, and Either.
Prelude Data.Either> let m = Just 7 Prelude Data.Either> :t m m :: Maybe Integer
Prelude Data.Either> let l = 2:[] Prelude Data.Either> :t l l :: [Integer]
Prelude Data.Either> let g = getLine Prelude Data.Either> :t g g :: IO String
Prelude Data.Either> let e = Right "abc" Prelude Data.Either> :t e e :: Either a [Char]
All these instances are functors, each with its own version of fmap that can be applied to it.
How can I similarly create an instance of (->) so I can apply (->)'s version of fmap
instance Functor ((->) r) where fmap f g = (\x -> f (g x))
to it?
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:50 PM 2010/8/31 michael rice
So it's a type constructor, not a type? Could you please provide a simple example of its usage?
Sure, although I'm sure you've come by some already.
-- the identity function id :: a -> a -- often, we write it like this: -- id x = x -- but here we see the relationship between the ananymous function syntax and the function type: id = \x -> x
In fact, if you write in prefix form, it is quite familiar: f :: (->) Int Bool e = Either String Float
Cheers, Thu
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:17 PM 2010/8/31 michael rice
"Learn You a Haskell ..." says that (->) is a type just like Either. Where can I find its type definition?
You can't define it *in* Haskell as user code. It is a built-in infix type constructor (Either or Maybe are type constructors too, not just types). In fact, if you want to implement a simple, typed functional language, you'll find it is the only built-in type constructor you have to implement (as the implementor of the language).
Also, Show a => a is a type too, but you won't find a definition for 'a' or for '=>'. All those things are defined by the language.
Cheers, Thu
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Aug 31, 2010, at 12:03 PM, michael rice wrote:
I tried creating an instance earlier but
*Main> :t (->) Int Char
<interactive>:1:1: parse error on input `->'
Try: Prelude> :info (->) data (->) a b -- Defined in GHC.Prim If you want type-information about values, use :t. If you want information about types (and the "type-level language"), use :info. This includes stuff like class definitions and instances in scope. For example, if I include Control.Monad: Prelude Control.Monad.Instances> :info (->) data (->) a b -- Defined in GHC.Prim instance Monad ((->) r) -- Defined in Control.Monad.Instances instance Functor ((->) r) -- Defined in Control.Monad.Instances :info is pretty cool: Prelude Control.Monad.Instances> :info Monad class Monad m where (>>=) :: m a -> (a -> m b) -> m b (>>) :: m a -> m b -> m b return :: a -> m a fail :: String -> m a -- Defined in GHC.Base instance Monad ((->) r) -- Defined in Control.Monad.Instances instance Monad Maybe -- Defined in Data.Maybe instance Monad [] -- Defined in GHC.Base instance Monad IO -- Defined in GHC.Base

FmapFunc is just a test module I created with
instance Functor ((->) r) where ...
-- ryan
On Tue, Aug 31, 2010 at 12:03 PM, michael rice
Hi, Ryan and all,
Bingo! I guess my question was all right after all.
I tried creating an instance earlier but
*Main> :t (->) Int Char
<interactive>:1:1: parse error on input `->'
What got loaded with FmapFunc? I Hoogled it and got back nothing.
Michael
--- On *Tue, 8/31/10, Ryan Ingram
* wrote: From: Ryan Ingram
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice"
Cc: "Vo Minh Thu" , haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 2:36 PM Prelude FmapFunc> let s = show :: ((->) Int) String Prelude FmapFunc> :t s s :: Int -> String Prelude FmapFunc> let v = fmap ("hello " ++) s Prelude FmapFunc> :t v v :: Int -> String Prelude FmapFunc> v 1 "hello 1"
-- ryan
On Tue, Aug 31, 2010 at 11:28 AM, michael rice
http://mc/compose?to=nowgate@yahoo.com wrote:
I'm not sure if my terminology is correct or even if my question makes sense, but I can create "instances" of Maybe, List, IO, and Either.
Prelude Data.Either> let m = Just 7 Prelude Data.Either> :t m m :: Maybe Integer
Prelude Data.Either> let l = 2:[] Prelude Data.Either> :t l l :: [Integer]
Prelude Data.Either> let g = getLine Prelude Data.Either> :t g g :: IO String
Prelude Data.Either> let e = Right "abc" Prelude Data.Either> :t e e :: Either a [Char]
All these instances are functors, each with its own version of fmap that can be applied to it.
How can I similarly create an instance of (->) so I can apply (->)'s version of fmap
instance Functor ((->) r) where fmap f g = (\x -> f (g x))
to it?
Michael
--- On *Tue, 8/31/10, Vo Minh Thu
http://mc/compose?to=noteed@gmail.com * wrote:
From: Vo Minh Thu
http://mc/compose?to=noteed@gmail.com Subject: Re: [Haskell-cafe] On to applicative To: "michael rice"
http://mc/compose?to=nowgate@yahoo.com Cc: haskell-cafe@haskell.orghttp://mc/compose?to=haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:50 PM
2010/8/31 michael rice
http://mc/compose?to=nowgate@yahoo.com So it's a type constructor, not a type? Could you please provide a simple
example of its usage?
Sure, although I'm sure you've come by some already.
-- the identity function id :: a -> a -- often, we write it like this: -- id x = x -- but here we see the relationship between the ananymous function syntax and the function type: id = \x -> x
In fact, if you write in prefix form, it is quite familiar: f :: (->) Int Bool e = Either String Float
Cheers, Thu
Michael
--- On Tue, 8/31/10, Vo Minh Thu
http://mc/compose?to=noteed@gmail.com> wrote: From: Vo Minh Thu
http://mc/compose?to=noteed@gmail.com Subject: Re: [Haskell-cafe] On to applicative To: "michael rice"
http://mc/compose?to=nowgate@yahoo.com Cc: haskell-cafe@haskell.orghttp://mc/compose?to=haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:17 PM
2010/8/31 michael rice
http://mc/compose?to=nowgate@yahoo.com "Learn You a Haskell ..." says that (->) is a type just like Either.
Where can I find its type definition?
You can't define it *in* Haskell as user code. It is a built-in infix type constructor (Either or Maybe are type constructors too, not just types). In fact, if you want to implement a simple, typed functional language, you'll find it is the only built-in type constructor you have to implement (as the implementor of the language).
Also, Show a => a is a type too, but you won't find a definition for 'a' or for '=>'. All those things are defined by the language.
Cheers, Thu
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mc/compose?to=Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

In each case, what does the notation
show:: ...
and
undefined:: ...
accomplish?
Prelude Control.Applicative> :t show::((->) Int) String
show::((->) Int) String :: Int -> String
Prelude Control.Applicative> :t undefined::((->) Int) String
undefined::((->) Int) String :: Int -> String
Michael
--- On Tue, 8/31/10, Ryan Ingram
So it's a type constructor, not a type? Could you please provide a simple example of its usage?
Sure, although I'm sure you've come by some already. -- the identity function id :: a -> a -- often, we write it like this: -- id x = x -- but here we see the relationship between the ananymous function syntax and the function type: id = \x -> x In fact, if you write in prefix form, it is quite familiar: f :: (->) Int Bool e = Either String Float Cheers, Thu
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote:
From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice"
Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:17 PM
2010/8/31 michael rice
"Learn You a Haskell ..." says that (->) is a type just like Either. Where can I find its type definition?
You can't define it *in* Haskell as user code. It is a built-in infix
type constructor (Either or Maybe are type constructors too, not just types). In fact, if you want to implement a simple, typed functional language, you'll find it is the only built-in type constructor you
have to implement (as the implementor of the language).
Also, Show a => a is a type too, but you won't find a definition for 'a' or for '=>'. All those things are defined by the language.
Cheers, Thu
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Sep 2, 2010, at 11:30 AM, michael rice wrote:
In each case, what does the notation
show:: ...
and
undefined:: ...
accomplish?
They're type annotations. show is a function in "many" types: Prelude> :t show show :: (Show a) => a -> String If you want to see the type of a "specific" show function, you need to find a way to "determine" its type. This is a slightly different function, but it's equivalent in types and semantics: Prelude> :t \x -> show x \x -> show x :: (Show a) => a -> String Now we have a named argument, and we can constraint its type with an annotation: Prelude> :t \x -> show (x :: Int) \x -> show (x :: Int) :: Int -> String

Hi Alexander,
Prelude FmapFunc> let s = show :: ((->) Int) String
Prelude FmapFunc> :t s
s :: Int -> String
The notation was throwing me, but after staring at it for a while it finally sunk in that show (above) is partially applied.
Thanks, all.
Michael
--- On Thu, 9/2/10, Alexander Solla

2010/8/31 michael rice
I'm not sure if my terminology is correct or even if my question makes sense, but I can create "instances" of Maybe, List, IO, and Either.
Prelude Data.Either> let m = Just 7 Prelude Data.Either> :t m m :: Maybe Integer
We say that m has type Maybe Integer, so :: is pronounced 'has type'. We also say that m is a value. Just is a type constructor, Maybe Int is a type, and Just 7, like m, is a value. So we don't talk about instance here. Informally you could say that 7 is an instance of Int, but in Haskell we use 'instance' to mean something (precisely) else. This pharse is correct w.r.t to the use of 'instance' in Haskell: Maybe is an instance of the Functor class.
Prelude Data.Either> let l = 2:[] Prelude Data.Either> :t l l :: [Integer]
Prelude Data.Either> let g = getLine Prelude Data.Either> :t g g :: IO String
Prelude Data.Either> let e = Right "abc" Prelude Data.Either> :t e e :: Either a [Char]
All these instances are functors, each with its own version of fmap that can be applied to it.
How can I similarly create an instance of (->) so I can apply (->)'s version of fmap
instance Functor ((->) r) where fmap f g = (\x -> f (g x))
to it?
Note that for Maybe, the instance is define with instance Functor Maybe where ... Note how the type argument of Maybe is not given. But above, when you create a value, it has type Maybe Int, not only Maybe. So for the ((->) r) case, you still want to "complete" it. E.g. m :: Maybe Int -- not just Maybe (+) :: (->) Int Int -- and not only (->) Int Cheers, Thu
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:50 PM 2010/8/31 michael rice
So it's a type constructor, not a type? Could you please provide a simple example of its usage?
Sure, although I'm sure you've come by some already.
-- the identity function id :: a -> a -- often, we write it like this: -- id x = x -- but here we see the relationship between the ananymous function syntax and the function type: id = \x -> x
In fact, if you write in prefix form, it is quite familiar: f :: (->) Int Bool e = Either String Float
Cheers, Thu
Michael
--- On Tue, 8/31/10, Vo Minh Thu
wrote: From: Vo Minh Thu
Subject: Re: [Haskell-cafe] On to applicative To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 31, 2010, 1:17 PM 2010/8/31 michael rice
"Learn You a Haskell ..." says that (->) is a type just like Either. Where can I find its type definition?
You can't define it *in* Haskell as user code. It is a built-in infix type constructor (Either or Maybe are type constructors too, not just types). In fact, if you want to implement a simple, typed functional language, you'll find it is the only built-in type constructor you have to implement (as the implementor of the language).
Also, Show a => a is a type too, but you won't find a definition for 'a' or for '=>'. All those things are defined by the language.
Cheers, Thu

michael rice wrote:
Prelude Data.Either> let m = Just 7 Prelude Data.Either> :t m m :: Maybe Integer
So to create a value of type (Maybe ...), you can use Just.
Prelude Data.Either> let l = 2:[] Prelude Data.Either> :t l l :: [Integer]
So to create a value of type [...], you can use (:) and [].
Prelude Data.Either> let g = getLine Prelude Data.Either> :t g g :: IO String
So to create a value of type (IO ...), you can use getLine.
Prelude Data.Either> let e = Right "abc" Prelude Data.Either> :t e e :: Either a [Char]
So to create a value of type (Either ... ...), you can use Right.
How can I similarly create an instance of (->) [...] ?
An "instance of (->)" is usually called a function. And functions are created by lambda abstraction: Prelude> let f = \x -> x Prelude> :t f f :: t -> t So to create a value of type (... -> ...), you can use \. Just like Either, -> is a binary type constructor. Just like (Either a b) is a type, (a -> b) is a type. And very much like you can create (Either a b) values with Left and Right, you can create (a -> b) values with \. Tillmann PS. After studying how to construct values, it may be instructive to study how to take them apart. For example, Bool values can be taken apart by if-then-else expressions. What about Either, IO and -> values?

Hi Tillman,
Prelude Control.Monad Control.Monad.Instances Control.Applicative> let f = \x -> x:[]
Prelude Control.Monad Control.Monad.Instances Control.Applicative> :t f
f :: a -> [a]
Prelude Control.Monad Control.Monad.Instances Control.Applicative> let g = \x -> Just x
Prelude Control.Monad Control.Monad.Instances Control.Applicative> :t g
g :: a -> Maybe a
Prelude Control.Monad Control.Monad.Instances Control.Applicative> :t z
z :: Integer -> Integer
Prelude Control.Monad Control.Monad.Instances Control.Applicative Data.Char> :t y
y :: Char -> Int
Can you think of a situation for
\x -> f x
that would require x to have a declared type, or is it always inferred by the type of f?
Michael
--- On Wed, 9/1/10, Tillmann Rendel
Prelude Data.Either> let m = Just 7 Prelude Data.Either> :t m m :: Maybe Integer
So to create a value of type (Maybe ...), you can use Just.
Prelude Data.Either> let l = 2:[] Prelude Data.Either> :t l l :: [Integer]
So to create a value of type [...], you can use (:) and [].
Prelude Data.Either> let g = getLine Prelude Data.Either> :t g g :: IO String
So to create a value of type (IO ...), you can use getLine.
Prelude Data.Either> let e = Right "abc" Prelude Data.Either> :t e e :: Either a [Char]
So to create a value of type (Either ... ...), you can use Right.
How can I similarly create an instance of (->) [...] ?
An "instance of (->)" is usually called a function. And functions are created by lambda abstraction: Prelude> let f = \x -> x Prelude> :t f f :: t -> t So to create a value of type (... -> ...), you can use \. Just like Either, -> is a binary type constructor. Just like (Either a b) is a type, (a -> b) is a type. And very much like you can create (Either a b) values with Left and Right, you can create (a -> b) values with \. Tillmann PS. After studying how to construct values, it may be instructive to study how to take them apart. For example, Bool values can be taken apart by if-then-else expressions. What about Either, IO and -> values?

Sorry, my last message got garbled. Hope this is better.
Prelude Control.Monad Control.Monad.Instances Control.Applicative> let f = \x -> x:[]
Prelude Control.Monad Control.Monad.Instances Control.Applicative> :t f
f :: a -> [a]
Prelude Control.Monad Control.Monad.Instances Control.Applicative> let g = \x -> Just x
Prelude Control.Monad Control.Monad.Instances Control.Applicative> :t g
g :: a -> Maybe a
=====
Prelude Control.Monad Control.Monad.Instances Control.Applicative> let z = \x -> x+1
Prelude Control.Monad Control.Monad.Instances Control.Applicative> :t z
z :: Integer -> Integer
Prelude Control.Monad Control.Monad.Instances Control.Applicative.Data.Char> let y = \x -> ord x
Prelude Control.Monad Control.Monad.Instances Control.Applicative Data.Char> :t y
y :: Char -> Int
Can you think of a situation for
\x -> f x
or
\x y z -> x + ord y - head z
that would require x (y z) to have their type(s) declared (ala Pascal), or is it always
inferred by what appears to the right of "->"?
I guess what I'm asking is can an anonymous function be given a type signature?
Michael
--- On Wed, 9/1/10, Tillmann Rendel
Prelude Data.Either> let m = Just 7 Prelude Data.Either> :t m m :: Maybe Integer
So to create a value of type (Maybe ...), you can use Just.
Prelude Data.Either> let l = 2:[] Prelude Data.Either> :t l l :: [Integer]
So to create a value of type [...], you can use (:) and [].
Prelude Data.Either> let g = getLine Prelude Data.Either> :t g g :: IO String
So to create a value of type (IO ...), you can use getLine.
Prelude Data.Either> let e = Right "abc" Prelude Data.Either> :t e e :: Either a [Char]
So to create a value of type (Either ... ...), you can use Right.
How can I similarly create an instance of (->) [...] ?
An "instance of (->)" is usually called a function. And functions are created by lambda abstraction: Prelude> let f = \x -> x Prelude> :t f f :: t -> t So to create a value of type (... -> ...), you can use \. Just like Either, -> is a binary type constructor. Just like (Either a b) is a type, (a -> b) is a type. And very much like you can create (Either a b) values with Left and Right, you can create (a -> b) values with \. Tillmann PS. After studying how to construct values, it may be instructive to study how to take them apart. For example, Bool values can be taken apart by if-then-else expressions. What about Either, IO and -> values?

On Thu, Sep 2, 2010 at 10:45 AM, michael rice
Can you think of a situation for
\x -> f x or \x y z -> x + ord y - head z
that would require x (y z) to have their type(s) declared (ala Pascal), or is it always inferred by what appears to the right of "->"?
I think Haskell 98 can always infer the type of an anonymous function. There are some extensions involving more advanced types that can't be inferred, but you don't need to worry about them yet.
I guess what I'm asking is can an anonymous function be given a type signature?
Sure. Just write (\x -> x + 1) :: Int -> Int. (The parentheses are
important. Without them, the type signature is given to the function body.)
I don't think I've ever needed to give a type for an anonymous function,
though. Generally, the context where the function is being used is
sufficient.
--
Dave Menendez

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 8/31/10 13:27 , michael rice wrote:
So it's a type constructor, not a type? Could you please provide a simple example of its usage?
Assuming you don't mean the trivial use in defining functions, see Control.Monad.Instances:
instance Functor ((->) r) where fmap = (.)
instance Monad ((->) r) where return = const f >>= k = \ r -> k (f r) r
(The above is the primitive reader functor/monad, see Control.Monad.Reader for more information.) - -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkx9Z4EACgkQIn7hlCsL25WgrwCgvFQlObavv1fNOaKDjB/qbk8t 8+IAoLUrenXFzZFfJoYYvSy00uPctnaE =ljiY -----END PGP SIGNATURE-----

Thanks, Brandon, but Ryan gave me what I was looking for.
Michael
--- On Tue, 8/31/10, Brandon S Allbery KF8NH
So it's a type constructor, not a type? Could you please provide a simple example of its usage?
Assuming you don't mean the trivial use in defining functions, see Control.Monad.Instances:
instance Functor ((->) r) where fmap = (.)
instance Monad ((->) r) where return = const f >>= k = \ r -> k (f r) r
(The above is the primitive reader functor/monad, see Control.Monad.Reader for more information.) - -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkx9Z4EACgkQIn7hlCsL25WgrwCgvFQlObavv1fNOaKDjB/qbk8t 8+IAoLUrenXFzZFfJoYYvSy00uPctnaE =ljiY -----END PGP SIGNATURE----- _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (8)
-
Alexander Solla
-
Brandon S Allbery KF8NH
-
Bulat Ziganshin
-
David Menendez
-
michael rice
-
Ryan Ingram
-
Tillmann Rendel
-
Vo Minh Thu