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. Exporting constructors (Patrick LeBoutillier)
2. Re: Exporting constructors (Daniel Fischer)
3. Re: how to feel free of the Implementation of Data structure
(aditya siram)
4. Re: Does haskell have to have values? (Brent Yorgey)
5. Re: how to feel free of the Implementation of Data structure
(Brent Yorgey)
6. Re: Exporting constructors (Brent Yorgey)
7. :kind (->) - What do the question marks imply? (Amitava Shee)
8. Re: :kind (->) - What do the question marks imply? (Brent Yorgey)
9. Re: how to feel free of the Implementation of Data structure
(???)
----------------------------------------------------------------------
Message: 1
Date: Thu, 24 Mar 2011 08:17:16 -0400
From: Patrick LeBoutillier <[email protected]>
Subject: [Haskell-beginners] Exporting constructors
To: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi all,
Is it possible to export constructors from a module in a way that they
can be used for pattern matching but not for creating types?
Patrick
--
=====================
Patrick LeBoutillier
Rosem?re, Qu?bec, Canada
------------------------------
Message: 2
Date: Thu, 24 Mar 2011 13:36:43 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Exporting constructors
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="iso-8859-1"
On Thursday 24 March 2011 13:17:16, Patrick LeBoutillier wrote:
> Hi all,
>
> Is it possible to export constructors from a module in a way that they
> can be used for pattern matching but not for creating types?
>
> Patrick
No, that's impossible (as far as I know). If a constructor is exported,
it's available for construction as well as for pattern matching.
------------------------------
Message: 3
Date: Thu, 24 Mar 2011 10:22:20 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] how to feel free of the
Implementation of Data structure
To: ??? <[email protected]>
Cc: haskell beginner <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
> 1. To use the Data.List is so easy as it's in the 'prelude'. but when
> I want to get some elements by index, I need to use Array, or sometime
> I want to use ByteString for some good reason.
> We all know It's some 'linear ordered things'. Is there some method
> for me to use just one form of 'list' with every possible function on
> it.
Edward Kmett has recently released the "keys" [1] package which
abstracts away data structures that can be indexed by providing an
Indexable typeclass. It's quite simple to use.
Here is example usage:
import Data.Key
import Data.Array hiding ((!))
import Data.ByteString.UTF8
testList = [1,2,3,4,5]
testArray = listArray (0,4) [1..]
testString = "12345"
main = do
byteString <- return $ fromString testString
string <- return testString
print $ testList ! 2
print $ testArray ! 2
print $ string ! 2
print $ (toString byteString) ! 2
*Main> main
3
3
'3'
'3'
In the example I have to import Data.Array with the "hiding"
constraint because (!) is exported by both Data.Array and Data.Key.
>
> 2.
> f1 :: (Integral a) => a -> String
> f2 :: (Integral a) => String -> a
>
> pipe = f1 . f2
> It is clear that pipe is String -> String,
> but.(1)How can I know what instance that 'a' is.
> ? ?(2)How can I determine what instance of 'a' is.
Withing f1 and f2 you cannot, all these functions know about is that
'a' implements functions in the typeclass Integral. There might be
some reflection magic that can get this information for you but I
don't think it is intended usage.
-deech
------------------------------
Message: 4
Date: Thu, 24 Mar 2011 11:41:05 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Does haskell have to have values?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Wed, Mar 23, 2011 at 04:17:57PM -0400, Mike Meyer wrote:
> I'm working my way through Real World haskell, and so far have found
> the experience quite pleasant (though the harder exercises seem to
> require things net yet covered).
>
> Among the comments in the IO chapter was a discussion of whether or
> not some monad was or was not a function, which got me thinking.
>
> Values in haskell aren't evaluated until they're needed. They're
> implemented as thunks, meaning they're roughly zeroadic functions that
> will return the value when called.
>
> The syntax of the language seems to make treating values as zeroadic
> functions that return the value in question a reasonable
> interpretation as a degenerate case:
>
> (+) accepts two arguments and returns their sum.
> (+ 5) accepts one argument and returns that plus 5.
> (3 + 5) accepts zero arguments and returns 8.
It makes sense as a degenerate case if you look at things this way...
> or (more pedantically):
>
> (+) accepts one argument and returns a function that accepts one
> argument and returns a zeroadic function that returns the
> value of the sum of the two arguments.
> (+ 5) accepts one argument and returns a zeroadic function that ...
> (3 + 5) a zeroadic function that returns 8
... but as you note, really all functions take *one* argument, so now
calling values "zero-argument" functions seems less like a degenerate
case and more just like a weird special case.
> So the question is - is there any advantage or harm in this way of
> looking at values?
However, I don't think it's really all that harmful, and may even give
you some good intuition for laziness. In a strict language, if you
want a lazy value of type T you can replace it by a function () -> T
-- which is sort of like a "zero-adic" function since it does take an
argument, but that argument contains no information.
-Brent
------------------------------
Message: 5
Date: Thu, 24 Mar 2011 11:43:56 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] how to feel free of the
Implementation of Data structure
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
On Thu, Mar 24, 2011 at 06:34:57PM +0800, ??? wrote:
>
> 2.
> f1 :: (Integral a) => a -> String
> f2 :: (Integral a) => String -> a
>
> pipe = f1 . f2
> It is clear that pipe is String -> String,
Actually, this code will give an "ambiguous type" error, since the
compiler cannot figure out what type 'a' should be. And the type that
is chosen may make a difference for the behavior.
> but.(1)How can I know what instance that 'a' is.
> (2)How can I determine what instance of 'a' is.
If you know what type you want to use for 'a' you can specify it with
a type annotation, like this:
pipe = f1 . (f2 :: String -> Int)
-Brent
------------------------------
Message: 6
Date: Thu, 24 Mar 2011 11:48:42 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Exporting constructors
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Thu, Mar 24, 2011 at 08:17:16AM -0400, Patrick LeBoutillier wrote:
> Hi all,
>
> Is it possible to export constructors from a module in a way that they
> can be used for pattern matching but not for creating types?
I would suggest exporting an 'eliminator' function for your data type
(like the functions 'maybe' and 'either'), which essentially allows the
user to do pattern-matching (although not with built-in pattern
matching syntax). For example, if your data type is
data Foo = Bar Int
| Baz Foo Char
| Quux
then you could export a function
matchFoo :: Foo -> (Int -> a) -> (Foo -> Char -> a) -> a -> a
which they could use like
matchFoo f
(\i -> ...) -- Bar case
(\f' c -> ...) -- Baz case
... -- Quux case
-Brent
------------------------------
Message: 7
Date: Thu, 24 Mar 2011 12:21:57 -0400
From: Amitava Shee <[email protected]>
Subject: [Haskell-beginners] :kind (->) - What do the question marks
imply?
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hello Haskell gurus,
I am trying to understand "kind"
Prelude> :k Maybe
Maybe :: * -> *
Prelude> :k (->)
(->) :: ?? -> ? -> *
What are the question marks? Why are they different from *? How is this
related to rank-2 polymorphism?
Thanks in advance,
Regards,
Amitava Shee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110324/2e095b59/attachment-0001.htm>
------------------------------
Message: 8
Date: Thu, 24 Mar 2011 12:46:06 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] :kind (->) - What do the question
marks imply?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Thu, Mar 24, 2011 at 12:21:57PM -0400, Amitava Shee wrote:
> Hello Haskell gurus,
>
> I am trying to understand "kind"
>
> Prelude> :k Maybe
> Maybe :: * -> *
> Prelude> :k (->)
> (->) :: ?? -> ? -> *
>
> What are the question marks? Why are they different from *?
I forget the precise details, but they are artifacts of GHC's
internals. They have something to do with strictness and/or
unboxing. You should really just think of them as if they were *.
> How is this
> related to rank-2 polymorphism?
It isn't, as far as I know.
-Brent
------------------------------
Message: 9
Date: Fri, 25 Mar 2011 12:32:43 +0800
From: ??? <[email protected]>
Subject: Re: [Haskell-beginners] how to feel free of the
Implementation of Data structure
To: Brent Yorgey <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
:) Thanks.
2011/3/24 Brent Yorgey <[email protected]>:
> On Thu, Mar 24, 2011 at 06:34:57PM +0800, ??? wrote:
>>
>> 2.
>> f1 :: (Integral a) => a -> String
>> f2 :: (Integral a) => String -> a
>>
>> pipe = f1 . f2
>> It is clear that pipe is String -> String,
>
> Actually, this code will give an "ambiguous type" error, since the
> compiler cannot figure out what type 'a' should be. ?And the type that
> is chosen may make a difference for the behavior.
>
>> but.(1)How can I know what instance that 'a' is.
>> ? ? (2)How can I determine what instance of 'a' is.
>
> If you know what type you want to use for 'a' you can specify it with
> a type annotation, like this:
>
> ?pipe = f1 . (f2 :: String -> Int)
>
> -Brent
>
> _______________________________________________
> 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 33, Issue 34
*****************************************