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. Why do class instance functions behave differently when
executed directly in WinGHCi than when loaded from a file?
(Costello, Roger L.)
2. Re: Why do class instance functions behave differently when
executed directly in WinGHCi than when loaded from a file?
(Daniel Fischer)
3. Re: Simple warp-based server (Michael Xavier)
4. Re: Options for creating a multiple select form via Yesod
(Michael Litchard)
5. Re: Options for creating a multiple select form via Yesod
(Michael Litchard)
6. Regex woes... (Sean Charles)
7. Re: Regex woes... (Daniel Fischer)
8. Profiling install error ([email protected])
----------------------------------------------------------------------
Message: 1
Date: Fri, 10 Jun 2011 06:53:30 -0400
From: "Costello, Roger L." <[email protected]>
Subject: [Haskell-beginners] Why do class instance functions behave
differently when executed directly in WinGHCi than when loaded from a
file?
To: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="us-ascii"
Hi Folks,
I created a file, and in the file I entered this type class and an instance:
class MyEqualityOperator a where
isEqual :: a -> a -> Bool
instance MyEqualityOperator Double where
isEqual x y = x == y
To test the isEqual function I entered this:
test = isEqual 3 4
When I loaded my file into WinGHCi, I got this error:
----------------------------------------------------------------------------
Ambiguous type variable `t' in the constraints:
`Num t'
arising from the literal `3' at simpleTypeClassTest.hs:11:14
`MyEqualityOperator t'
arising from a use of `isEqual' at simpleTypeClassTest.hs:11:5-16
Probable fix: add a type signature that fixes these type variable(s)
----------------------------------------------------------------------------
Why is it "ambiguous"?
Interestingly, when I typed this at the WinGHCi command prompt:
isEqual 3 4
I got no error and I got the expected result (False).
Why is this?
What would I need to do, in my file, to make this work properly:
test = isEqual 3 4
/Roger
------------------------------
Message: 2
Date: Fri, 10 Jun 2011 13:50:17 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Why do class instance functions
behave differently when executed directly in WinGHCi than when loaded
from a file?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="us-ascii"
On Friday 10 June 2011, 12:53:30, Costello, Roger L. wrote:
> Hi Folks,
>
> I created a file, and in the file I entered this type class and an
> instance:
>
> class MyEqualityOperator a where
> isEqual :: a -> a -> Bool
>
> instance MyEqualityOperator Double where
> isEqual x y = x == y
>
> To test the isEqual function I entered this:
>
> test = isEqual 3 4
>
> When I loaded my file into WinGHCi, I got this error:
>
> ------------------------------------------------------------------------
> ---- Ambiguous type variable `t' in the constraints:
> `Num t'
> arising from the literal `3' at simpleTypeClassTest.hs:11:14
> `MyEqualityOperator t'
> arising from a use of `isEqual' at
> simpleTypeClassTest.hs:11:5-16 Probable fix: add a type signature that
> fixes these type variable(s)
> -----------------------------------------------------------------------
> -----
>
> Why is it "ambiguous"?
The end is "because the type checker works with an open-world assumption
and hence doesn't use the instances in scope to determine the type".
Before that comes
- numeric literals are polymorphic, the literal 3 stand for (fromInteger 3)
and has type (Num t) => t
So the type checker sees
3 :: Num t => t
4 :: Num n => n
Those are arguments to
isEqual :: MyEqualityOperator a => a -> a -> Bool
hence n = t, but the type checker still doesn't know which type that is, it
only has the constraint
3 :: (Num t, MyEqualityOperator t) => t
(and 4 has the same type).
Now, that's harmless so far, but test = isEqual 3 4 now gets the type
test :: (Num t, MyEqualityOperator t) => Bool
and here you have a type variable, t, in the constraints which doesn't
appear on the right hand side, thus that is an ambiguous type.
Now, if the type checker took the instances in scope into account, it could
find that the only instance of MyEqualityOperator in scope is for Double,
resove t to Double and be done with it.
But, then somebody imports that module in a module where also an
instance MyEqualityOperator Int where...
is in scope, and test now becomes unresolvable - that's why the type
checker cannot use the instances in scope to determine the types involved,
things might be imported in environments with other instances in scope and
that would break stuff.
Now, if you had
test2 = 3 == 4
in your source file, that would compile without an ambiguous type variable
error.
But that's almost the same as test, the only difference is that the
inferred type for test2 is
test2 :: (Num t, Eq t) => Bool
What's going on?
Under certain circumstances, such ambiguous type variables are resoved by
defaulting (cf. section 4.3.4 [iirc] of the language report).
The conditions are
- all constraints are of the form (Cls v)
- at least one of the constraints involves a numeric class
- all involved classes are defined in the Prelude or the standard libraries
These conditions are fulfilled for test2, so there the type variable t gets
defaulted to Integer [unless you have a default declaration in your module
overriding the default default].
For test, the third condition is not fulfilled, so the ambiguity does not
get resolved by defaulting.
>
> Interestingly, when I typed this at the WinGHCi command prompt:
>
> isEqual 3 4
>
> I got no error and I got the expected result (False).
>
> Why is this?
Because ghci uses extended defaulting rules.
At the prompt, there's less context to determine type variables than in
code, so ambiguous situations arise more often. To reduce the frequency of
ambiguous type errors, ghci uses defaulting also in situations not covered
by the report.
>
> What would I need to do, in my file, to make this work properly:
>
> test = isEqual 3 4
Provide a type annotation,
test = isEqual 3 (4 :: Double)
>
>
> /Roger
------------------------------
Message: 3
Date: Fri, 10 Jun 2011 08:16:15 -0700
From: Michael Xavier <[email protected]>
Subject: Re: [Haskell-beginners] Simple warp-based server
To: Michael Snoyman <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Thanks! That tutorial is perfect for what I was trying to do. I still find
it kind of weird coming from my background that an Application which
reads/modifies the request body would ignore the request but it makes
perfect sense after having read a bit more about WAI/Warp to know that the
request doesn't really have the body in it.
Thanks for the help and all the great software!
--
Michael Xavier
http://www.michaelxavier.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110610/3fb69408/attachment-0001.htm>
------------------------------
Message: 4
Date: Fri, 10 Jun 2011 13:24:53 -0700
From: Michael Litchard <[email protected]>
Subject: Re: [Haskell-beginners] Options for creating a multiple
select form via Yesod
To: Michael Snoyman <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Ah yes, I was thinking along the lines of making a contribution to the
codebase in this way. My thinking was that making a jQuery widget
would be the easiest path to that end. But I will follow your advice
instead.
On Thu, Jun 9, 2011 at 10:05 PM, Michael Snoyman <[email protected]> wrote:
> Hi Michael,
>
> There's nothing jQuery or Javascript specific about a multi-select
> field: it's just a normal select field with a "multiple" attribute. I
> would recommend taking the selectField code from yesod-form and
> modifying it to be multi-select. I'll likely do this myself
> eventually, but it could be a good learning experience in Yesod (and a
> great introduction to contributing to the framework if you're so
> inclined).
>
> Michael
>
> On Thu, Jun 9, 2011 at 8:29 PM, Michael Litchard <[email protected]> wrote:
>> I'm trying to create a multiple select form, as illustrated on the following:
>> http://api.jquery.com/selected-selector/
>>
>> Here's the options I see possible:
>>
>> (1) Write a jQuery widget.
>> (2) Use plain javascript via Julius
>> (3) Use the low-level functions in Yesod.Form to write a widget
>> (4) Use a pre-existing function that does what I need, but am not
>> aware of this functionality
>>
>> (1) has appeal as it looks like something small I can contribute to
>> the project. It will take me some extra time to figure out the
>> details. But, I had a look at the other jQuery widgets and they seem
>> to provide an approachable model to follow.
>>
>> (2) This looks like the most straight-forward approach. I'm just
>> learning javascript so would have to figure out how to capture values
>> in Haskell from the form.
>>
>> (3) This looks like the most difficult way. I don't think I know
>> enough about the low-level functions in Yesod.Form to be able to
>> accomplish this in a timely manner.
>>
>> (4) This is the best scenario. There's already a way to do this right
>> now, and I just haven't identified it. If this is the case, I would
>> appreciate being pointed in the right direction.
>>
>> Until informed otherwise, I'm evaluating options 1 and 2. All feedback
>> welcomed. Thanks to all who made Yesod possible.
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
------------------------------
Message: 5
Date: Fri, 10 Jun 2011 15:14:49 -0700
From: Michael Litchard <[email protected]>
Subject: Re: [Haskell-beginners] Options for creating a multiple
select form via Yesod
To: Michael Snoyman <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hey! I just added multiSelectField to the Forms library. I'm only
getting the first value selected, but I think that's because of how
I'm using multiSelecrField. I'm going to try to change the client code
to fix this. I'll let you know how it goes. when I get a
maybeMultiSelectField added I'll show you what I have. What would be
the best way to submit this?
On Thu, Jun 9, 2011 at 10:05 PM, Michael Snoyman <[email protected]> wrote:
> Hi Michael,
>
> There's nothing jQuery or Javascript specific about a multi-select
> field: it's just a normal select field with a "multiple" attribute. I
> would recommend taking the selectField code from yesod-form and
> modifying it to be multi-select. I'll likely do this myself
> eventually, but it could be a good learning experience in Yesod (and a
> great introduction to contributing to the framework if you're so
> inclined).
>
> Michael
>
> On Thu, Jun 9, 2011 at 8:29 PM, Michael Litchard <[email protected]> wrote:
>> I'm trying to create a multiple select form, as illustrated on the following:
>> http://api.jquery.com/selected-selector/
>>
>> Here's the options I see possible:
>>
>> (1) Write a jQuery widget.
>> (2) Use plain javascript via Julius
>> (3) Use the low-level functions in Yesod.Form to write a widget
>> (4) Use a pre-existing function that does what I need, but am not
>> aware of this functionality
>>
>> (1) has appeal as it looks like something small I can contribute to
>> the project. It will take me some extra time to figure out the
>> details. But, I had a look at the other jQuery widgets and they seem
>> to provide an approachable model to follow.
>>
>> (2) This looks like the most straight-forward approach. I'm just
>> learning javascript so would have to figure out how to capture values
>> in Haskell from the form.
>>
>> (3) This looks like the most difficult way. I don't think I know
>> enough about the low-level functions in Yesod.Form to be able to
>> accomplish this in a timely manner.
>>
>> (4) This is the best scenario. There's already a way to do this right
>> now, and I just haven't identified it. If this is the case, I would
>> appreciate being pointed in the right direction.
>>
>> Until informed otherwise, I'm evaluating options 1 and 2. All feedback
>> welcomed. Thanks to all who made Yesod possible.
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
------------------------------
Message: 6
Date: Fri, 10 Jun 2011 23:15:43 +0100
From: Sean Charles <[email protected]>
Subject: [Haskell-beginners] Regex woes...
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
I did a cabal update then:
cabal install regex-base
cabal install regex-compat
cabal install regex-posix
Everything built and installed, there were no errors as far as I could
tell. However, on attempting to get into regex on page 199 of my Real
World Haskell book I get this error when trying to use [String] as the
return type and I don't know why...
GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> :m Text.Regex.Posix
Prelude Text.Regex.Posix>
Prelude Text.Regex.Posix> "this is the string" =~ "th" :: [String]
<interactive>:1:0:
No instance for (RegexContext Regex [Char] [String])
arising from a use of `=~' at <interactive>:1:0-27
Possible fix:
add an instance declaration for
(RegexContext Regex [Char] [String])
In the expression: "this is the string" =~ "th" :: [String]
In the definition of `it':
it = "this is the string" =~ "th" :: [String]
Prelude Text.Regex.Posix>
I am trying to write a page scraper, I've already sucked pages with
Network.HTTP and I thought it'd be easy to get the anchor tags!
------------------------------
Message: 7
Date: Sat, 11 Jun 2011 00:34:00 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Regex woes...
To: [email protected]
Cc: Sean Charles <[email protected]>
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="us-ascii"
On Saturday 11 June 2011, 00:15:43, Sean Charles wrote:
> I did a cabal update then:
> cabal install regex-base
> cabal install regex-compat
> cabal install regex-posix
>
> Everything built and installed, there were no errors as far as I could
> tell. However, on attempting to get into regex on page 199 of my Real
> World Haskell book I get this error when trying to use [String] as the
> return type and I don't know why...
>
>
> GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help
> Loading package ghc-prim ... linking ... done.
> Loading package integer-gmp ... linking ... done.
> Loading package base ... linking ... done.
> Loading package ffi-1.0 ... linking ... done.
> Prelude> :m Text.Regex.Posix
> Prelude Text.Regex.Posix>
>
> Prelude Text.Regex.Posix> "this is the string" =~ "th" :: [String]
>
> <interactive>:1:0:
> No instance for (RegexContext Regex [Char] [String])
> arising from a use of `=~' at <interactive>:1:0-27
> Possible fix:
> add an instance declaration for
> (RegexContext Regex [Char] [String])
> In the expression: "this is the string" =~ "th" :: [String]
> In the definition of `it':
> it = "this is the string" =~ "th" :: [String]
> Prelude Text.Regex.Posix>
>
>
> I am trying to write a page scraper, I've already sucked pages with
> Network.HTTP and I thought it'd be easy to get the anchor tags!
I'm not familiar with the regex libraries, but that's come up occasionally.
No idea whether it's an error in RWH or a change in the libs.
IIRC, it works with a result type of [[String]] (and several others, cf.
http://hackage.haskell.org/packages/archive/regex-
base/0.93.2/doc/html/Text-Regex-Base-RegexLike.html#t:RegexContext )
------------------------------
Message: 8
Date: Fri, 10 Jun 2011 18:43:43 -0700
From: [email protected]
Subject: [Haskell-beginners] Profiling install error
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
I'm trying to install the profiling version of the base libraries on
Fedora 15. I set the profiling options in ~/.cabal/config then tried to
reinstall but I get
%cabal install base --reinstall
Resolving dependencies...
cabal: internal error: impossible
Is there anything I can do now?
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 36, Issue 28
*****************************************