Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: a bunch o' questions (Brandon S Allbery KF8NH)
2. Re: a bunch o' questions (matthew coolbeth)
3. Re: a bunch o' questions (Brandon S Allbery KF8NH)
4. Re: a bunch o' questions (Daniel Fischer)
5. functor declaration (Michael Mossey)
6. Re: functor declaration (Isaac Dupree)
7. Re: functor declaration (Daniel Fischer)
8. the role of assignments (prad)
9. Re: the role of assignments (Jordan Cooper)
----------------------------------------------------------------------
Message: 1
Date: Thu, 01 Jul 2010 13:56:54 -0400
From: Brandon S Allbery KF8NH <[email protected]>
Subject: Re: [Haskell-beginners] a bunch o' questions
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 7/1/10 12:32 , Michael Mossey wrote:
> Regarding (->):
>
> - Is (->) a type constructor parameterized by two types?
> - Is (->) an operator? If so, it is the only operator that is also a type
> constructor?
Yes to both, at least in Haskell 98.
- --
brandon s. allbery [linux,solaris,freebsd,perl] [email protected]
system administrator [openafs,heimdal,too many hats] [email protected]
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/
iEYEARECAAYFAkws1uYACgkQIn7hlCsL25WfzwCfe7KbeMhuPM6JFU2NIQAG3tps
mA4AoNIZoKdvIO4eL7OkKwRmLtDhtSor
=BwP/
-----END PGP SIGNATURE-----
------------------------------
Message: 2
Date: Thu, 1 Jul 2010 14:48:05 -0400
From: matthew coolbeth <[email protected]>
Subject: Re: [Haskell-beginners] a bunch o' questions
To: Brandon S Allbery KF8NH <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
So, is it possible for me to define a parametric type with an infix binary
data constructor?
On Thu, Jul 1, 2010 at 13:56, Brandon S Allbery KF8NH
<[email protected]>wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 7/1/10 12:32 , Michael Mossey wrote:
> > Regarding (->):
> >
> > - Is (->) a type constructor parameterized by two types?
> > - Is (->) an operator? If so, it is the only operator that is also a
> type
> > constructor?
>
> Yes to both, at least in Haskell 98.
>
> - --
> brandon s. allbery [linux,solaris,freebsd,perl] [email protected]
> system administrator [openafs,heimdal,too many hats] [email protected]
> 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/
>
> iEYEARECAAYFAkws1uYACgkQIn7hlCsL25WfzwCfe7KbeMhuPM6JFU2NIQAG3tps
> mA4AoNIZoKdvIO4eL7OkKwRmLtDhtSor
> =BwP/
> -----END PGP SIGNATURE-----
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
mac
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100701/61a4c27e/attachment-0001.html
------------------------------
Message: 3
Date: Thu, 01 Jul 2010 15:00:08 -0400
From: Brandon S Allbery KF8NH <[email protected]>
Subject: Re: [Haskell-beginners] a bunch o' questions
To: matthew coolbeth <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 7/1/10 14:48 , matthew coolbeth wrote:
> So, is it possible for me to define a parametric type with an infix binary
> data constructor?
With the appropriate extension, you can declare an infix type or data
constructor using a symbol starting with `:':
> data Listy a = Nil | a :*: Listy a
http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/data-type-extensions.html#infix-tycons
- --
brandon s. allbery [linux,solaris,freebsd,perl] [email protected]
system administrator [openafs,heimdal,too many hats] [email protected]
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/
iEYEARECAAYFAkws5bgACgkQIn7hlCsL25VhEACgxv82olCE0gdBxjRVx+1Gqvv2
nkgAn1UJ5dGCza6qfW+FK7POSOcFY96F
=PT6o
-----END PGP SIGNATURE-----
------------------------------
Message: 4
Date: Thu, 1 Jul 2010 21:31:52 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] a bunch o' questions
To: [email protected], matthew coolbeth <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
On Thursday 01 July 2010 21:00:08, Brandon S Allbery KF8NH wrote:
> On 7/1/10 14:48 , matthew coolbeth wrote:
> > So, is it possible for me to define a parametric type with an infix
> > binary data constructor?
>
> With the appropriate extension, you can declare an infix type or data
To clarify: for infix data constructors, no extension is needed, they're in
Haskell98. To define and infix type constructor, you need the TypeOperators
language extension.
>
> constructor using a symbol starting with `:':
> > data Listy a = Nil | a :*: Listy a
^ Haskell98
{-# LANGUAGE TypeOperators #-}
data a :+: b = a :+: b deriving (Eq, Ord, Show)
^ not H98
>
> http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/data-type-extens
>ions.html#infix-tycons
------------------------------
Message: 5
Date: Thu, 01 Jul 2010 15:52:47 -0700
From: Michael Mossey <[email protected]>
Subject: [Haskell-beginners] functor declaration
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
in the declaration of Functor:
class Functor f where
fmap :: (a -> b) -> f a -> f b
does the compiler infer that f is a type constructor (not a type) because
of the appearance of "f a" and "f b"?
What I'm thinking is that some classes are classes of types, not type
constructors. Like
class CanMakeInt a where
makeInt :: a -> Int
In this case a is a type, not a type constructor. But there is no
difference in the form of the first line of the class declaration.
Thanks,
Mike
------------------------------
Message: 6
Date: Thu, 01 Jul 2010 19:13:39 -0400
From: Isaac Dupree <[email protected]>
Subject: Re: [Haskell-beginners] functor declaration
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
On 07/01/10 18:52, Michael Mossey wrote:
> in the declaration of Functor:
>
> class Functor f where
> fmap :: (a -> b) -> f a -> f b
>
> does the compiler infer that f is a type constructor (not a type)
> because of the appearance of "f a" and "f b"?
>
> What I'm thinking is that some classes are classes of types, not type
> constructors. Like
>
> class CanMakeInt a where
> makeInt :: a -> Int
>
> In this case a is a type, not a type constructor. But there is no
> difference in the form of the first line of the class declaration.
You are entirely correct! The compiler infers this from the entire
class declaration (or maybe it's the entire module). The fact that f is
a type-constructor, or a type, or whatever: that's its "kind", and this
process the compiler does is called "kind inference". Only rarely can
the compiler not figure it out, in which case (per standard) it defaults
to * (the 'kind' of ordinary types). (If you use an extension you can
also specify kinds explicitly, IIRC, like
class Functor (f :: * -> *) where
...
)
------------------------------
Message: 7
Date: Fri, 2 Jul 2010 01:28:20 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] functor declaration
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On Friday 02 July 2010 00:52:47, Michael Mossey wrote:
> in the declaration of Functor:
>
> class Functor f where
> fmap :: (a -> b) -> f a -> f b
>
> does the compiler infer that f is a type constructor (not a type)
> because of the appearance of "f a" and "f b"?
Yes. The compiler infers the kind of f from the signature of fmap.
Specifically, it infers that f must be a unary type constructor of
kind (* -> *).
* is the kind of types (or nullary type constructors).
Since a and b appear as arguments of (->), the compiler infers that a and b
both have kind *.
Later, f a and f b appear as arguments of (->), so f a and f b also must
have kind *, which means that f has kind * -> * (f takes one argument which
is a type and produces a type).
>
> What I'm thinking is that some classes are classes of types, not type
> constructors. Like
>
> class CanMakeInt a where
> makeInt :: a -> Int
>
> In this case a is a type, not a type constructor. But there is no
> difference in the form of the first line of the class declaration.
Right. But the compiler takes the methods of the class and their signatures
into account, which usually determine the kind of the class parameter (if
not, well...).
Here, a is an argument of (->), hence a must have kind *, i.e. be a type.
>
> Thanks,
> Mike
------------------------------
Message: 8
Date: Thu, 1 Jul 2010 16:59:35 -0700
From: prad <[email protected]>
Subject: [Haskell-beginners] the role of assignments
To: haskellbeginners <[email protected]>
Message-ID: <20100701165935.6bd4e...@gom>
Content-Type: text/plain; charset=US-ASCII
i'm trying to sort the assignment concept out in my mind.
as i understand it so far,
<- is for IO
so you can do something like
someIOVar <- readFile filename
this will be of type IO String
which is different from String as in
let someStrVar = "this is a string"
to work with an IO String you need to convert it into a String which
seems to automatically happen inside a do structure as in:
main = do
tmplX <- readFile "zztmpl.htm"
navbx <- readFile "zznavb.htm"
let page = U.replace tmplX "NAVX" navbx
are there some other ways to make IO String into String?
also, it seems that assignment is different for the '=' in a program vs
ghci for functions:
sum x y = x + y (program)
vs
let sum x y = x + y (ghci)
but not for strings and other things because you must always preface
assignment of values with 'let':
let a = 4
i suppose the let is there for variable assignments because such things
necessitate a change of state and i've read that this is not desirable
in functional programming - you have to work a little harder to do
assignment than languages which just allow
a = 4
b = 5
c = 6
etc
in haskell, is it preferable to do something like this:
var <- readFile fn
someFunction var
or someFunction (readFile fn)
--
In friendship,
prad
... with you on your journey
Towards Freedom
http://www.towardsfreedom.com (website)
Information, Inspiration, Imagination - truly a site for soaring I's
------------------------------
Message: 9
Date: Thu, 1 Jul 2010 17:04:21 -0700
From: Jordan Cooper <[email protected]>
Subject: Re: [Haskell-beginners] the role of assignments
To: prad <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
<- isn't just for IO; it's part of "do" notation's syntactic sugar. It
is actually (in your first example) passing the unwrapped result
(String; not IO String) of ``readFile filename" to an anonymous
function.
I'd recommend reading ch. 14 of Real World Haskell (
http://book.realworldhaskell.org/read/monads.html )
On 7/1/10, prad <[email protected]> wrote:
> i'm trying to sort the assignment concept out in my mind.
> as i understand it so far,
>
> <- is for IO
> so you can do something like
> someIOVar <- readFile filename
> this will be of type IO String
>
> which is different from String as in
>
> let someStrVar = "this is a string"
>
> to work with an IO String you need to convert it into a String which
> seems to automatically happen inside a do structure as in:
>
> main = do
> tmplX <- readFile "zztmpl.htm"
> navbx <- readFile "zznavb.htm"
> let page = U.replace tmplX "NAVX" navbx
>
> are there some other ways to make IO String into String?
>
>
>
> also, it seems that assignment is different for the '=' in a program vs
> ghci for functions:
>
> sum x y = x + y (program)
> vs
> let sum x y = x + y (ghci)
>
> but not for strings and other things because you must always preface
> assignment of values with 'let':
>
> let a = 4
>
> i suppose the let is there for variable assignments because such things
> necessitate a change of state and i've read that this is not desirable
> in functional programming - you have to work a little harder to do
> assignment than languages which just allow
> a = 4
> b = 5
> c = 6
> etc
>
> in haskell, is it preferable to do something like this:
>
> var <- readFile fn
> someFunction var
>
> or someFunction (readFile fn)
>
>
> --
> In friendship,
> prad
>
> ... with you on your journey
> Towards Freedom
> http://www.towardsfreedom.com (website)
> Information, Inspiration, Imagination - truly a site for soaring I's
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 25, Issue 3
****************************************