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: Haskell typing question (Cui Liqiang)
2. Re: Haskell typing question (Henk-Jan van Tuyl)
3. Re: Installation problems (Jeffrey Brown)
----------------------------------------------------------------------
Message: 1
Date: Tue, 28 Oct 2014 20:08:34 +0800
From: Cui Liqiang <[email protected]>
To: [email protected], [email protected]
Subject: Re: [Haskell-beginners] Haskell typing question
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
I got it!
The msg ? No instance for (Fractional Int) arising from a use of `/? ? actually
has no business with the operands order at all !
--
Cui Liqiang
On Tuesday, October 28, 2014 at 8:00 PM, Cui Liqiang wrote:
> Thanks for your help, your suggestion works.
>
> But I still don?t quite understand. In the following line:
> caluDecimal l = (foldr1 (\x acc -> acc / 10.0 + x) (map digitToInt l)),
> After applying digitToInt, the type of ?x? in the expression above is Int
> indeed, but Haskell consider the ?10.0? to be a Int, is it?
>
>
>
>
> ----------------------------------------------------------------------------------------------------------------------------
> Hi,
> I am doing an exercise in Haskell, which is converting a string like
> ?$123.312? to double value. Below is my code:
>
> module Main where
> import Data.Char
>
> caluInt l = foldl1 (\acc x -> acc * 10 + x) (map digitToInt l)
> caluDecimal l = (foldr1 (\x acc -> acc / 10.0 + x) (map digitToInt l))
>
> convert(x:xs) =
> let num = [e | e <- xs, e /= ',']
> intPart = takeWhile (/='.') num
> decimalPart = tail(dropWhile (/='.') num)
> in (caluInt intPart) + (caluDecimal decimalPart)
>
>
> And I got an error in this line: caluDecimal l = (foldr1 (\x acc -> acc /
> 10.0 + x) (map digitToInt l)),
> which says:
> No instance for (Fractional Int) arising from a use of `/'
> Possible fix: add an instance declaration for (Fractional Int)
> In the first argument of `(+)', namely `acc / 10.0'
> In the expression: acc / 10.0 + x
> In the first argument of `foldr1', namely
> `(\ x acc -> acc / 10.0 + x)'
>
>
> Why Haskell insists that 10.0 is a Int? How can I explicitly tell Haskell I
> want a Fractional?
> --
> Cui Liqiang
>
>
>
> > Why Haskell insists that 10.0 is a Int? How can I explicitly tell Haskell
> > I want a Fractional?
> >
>
>
> Because digitToInt means exactly what it says. If you want it to become
> something other than Int, apply fromIntegral to its result.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20141028/8b3c4146/attachment-0001.html>
------------------------------
Message: 2
Date: Tue, 28 Oct 2014 14:38:51 +0100
From: "Henk-Jan van Tuyl" <[email protected]>
To: [email protected], [email protected], "Cui Liqiang"
<[email protected]>
Subject: Re: [Haskell-beginners] Haskell typing question
Message-ID: <op.xofz66v3pz0j5l@alquantor>
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes
In the expression
\x acc -> acc / 10.0 + x
10.0 is a Fractional number, / is an operator that works on types in the
class Fractional, x is an Int, because the expression is applied to an Int.
To get the types correct, use fromIntegral:
caluDecimal l = (foldr1 (\x acc -> acc / 10.0 + x) (map (fromIntegral .
digitToInt) l))
(note, that you can write 10 instead of 10.0, with the same result.)
Regards,
Henk-Jan van Tuyl
On Tue, 28 Oct 2014 13:08:34 +0100, Cui Liqiang <[email protected]>
wrote:
> I got it!
>
> The msg ? No instance for (Fractional Int) arising from a use of `/? ?
> actually has no business with the operands order at all !
>
> --
> Cui Liqiang
>
>
> On Tuesday, October 28, 2014 at 8:00 PM, Cui Liqiang wrote:
>
>> Thanks for your help, your suggestion works.
>>
>> But I still don?t quite understand. In the following line:
>> caluDecimal l = (foldr1 (\x acc -> acc / 10.0 + x) (map digitToInt l)),
>> After applying digitToInt, the type of ?x? in the expression above is
>> Int indeed, but Haskell consider the ?10.0? to be a Int, is it?
>>
>>
>>
>>
>> ----------------------------------------------------------------------------------------------------------------------------
>> Hi,
>> I am doing an exercise in Haskell, which is converting a string like
>> ?$123.312? to double value. Below is my code:
>>
>> module Main where
>> import Data.Char
>>
>> caluInt l = foldl1 (\acc x -> acc * 10 + x) (map digitToInt l)
>> caluDecimal l = (foldr1 (\x acc -> acc / 10.0 + x) (map digitToInt l))
>>
>> convert(x:xs) =
>> let num = [e | e <- xs, e /= ',']
>> intPart = takeWhile (/='.') num
>> decimalPart = tail(dropWhile (/='.') num)
>> in (caluInt intPart) + (caluDecimal decimalPart)
>>
>>
>> And I got an error in this line: caluDecimal l = (foldr1 (\x acc -> acc
>> / 10.0 + x) (map digitToInt l)),
>> which says:
>> No instance for (Fractional Int) arising from a use of `/'
>> Possible fix: add an instance declaration for (Fractional Int)
>> In the first argument of `(+)', namely `acc / 10.0'
>> In the expression: acc / 10.0 + x
>> In the first argument of `foldr1', namely
>> `(\ x acc -> acc / 10.0 + x)'
>>
>>
>> Why Haskell insists that 10.0 is a Int? How can I explicitly tell
>> Haskell I want a Fractional?
:
>> Because digitToInt means exactly what it says. If you want it to become
>> something other than Int, apply fromIntegral to its result.
>>
>>
>
>
--
Folding@home
What if you could share your unused computer power to help find a cure? In
just 5 minutes you can join the world's biggest networked computer and get
us closer sooner. Watch the video.
http://folding.stanford.edu/
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--
------------------------------
Message: 3
Date: Tue, 28 Oct 2014 11:59:36 -0700
From: Jeffrey Brown <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Installation problems
Message-ID:
<caec4ma0tm_x+g15lymkf-kacsd0pdg-1iwdh-baxt6-okwm...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Problem solved. I reinstalled Mac OS 10.9, retaining no programs or
settings, just ordinary user-land files. Now everything works beautifully :)
On Sat, Oct 25, 2014 at 11:04 AM, Jeffrey Brown <[email protected]>
wrote:
> Hi,
>
> In trying to install Tidal, following something that worked for someone
> else who was getting an error similar to one I got, I ran
> ghc-clang-wrapper
> <https://gist.github.com/mzero/7245290#file-ghc-clang-wrapper>. I believe
> it was after that that cabal install stopped working, and I lost a lot of
> libraries that used to exist, such as Sound.MIDI:
>
> GHCi, version 7.8.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.
> Prelude> import Sound.MIDI
>
> <no location info>:
> Could not find module ?Sound.MIDI?
> It is not a module in the current program, or in any known package.
> Prelude>
>
> When I try to reinstall a library that used to exist -- e.g. "hosc", below
> -- via cabal install, I now get a giant slew of failures.
>
> Any ideas?
>
> Many thanks,
> Jeff
>
> sh-3.2# cabal install hosc
> Resolving dependencies...
> In order, the following will be installed:
> binary-0.7.2.2 (new version)
> data-binary-ieee754-0.4.4 (reinstall) changes: base-4.7.0.1 added,
> binary-0.7.2.2 added
> network-2.6.0.2 (new package)
> text-1.2.0.0 (new package)
> blaze-builder-0.3.3.4 (reinstall) changes: base-4.7.0.1 added,
> bytestring-0.10.4.0 added, text-1.2.0.0 added
> hosc-0.15 (new version)
> Warning: Note that reinstalls are always dangerous. Continuing
> anyway...
> Downloading binary-0.7.2.2...
> Configuring network-2.6.0.2...
> Configuring text-1.2.0.0...
> Failed to install network-2.6.0.2
> Build log ( /var/root/.cabal/logs/network-2.6.0.2.log ):
> Failed to install text-1.2.0.0
> Build log ( /var/root/.cabal/logs/text-1.2.0.0.log ):
> Configuring binary-0.7.2.2...
> Failed to install binary-0.7.2.2
> Build log ( /var/root/.cabal/logs/binary-0.7.2.2.log ):
> cabal: Error: some packages failed to install:
> binary-0.7.2.2 failed during the configure step. The exception was:
> user error (<command line>: cannot satisfy -package-id
> Cabal-1.20.0.2-b862897337f86101d0e1a35135984eff:
> Cabal-1.20.0.2-b862897337f86101d0e1a35135984eff is unusable due to
> missing or
> recursive dependencies:
> base-4.7.0.1-df210ede1eb79477fef5662549c32927
> bytestring-0.10.4.0-4aa78c8ca7b6b65993eefc131f7d94fa
> containers-0.5.5.1-0d8db9193d3e3371e0142bcc8a4a0721
> deepseq-1.3.0.2-8f63133c1b77f3b3190f04893cf340e4
> directory-1.2.1.0-af5afa2b9b551d3fec1a32d6bfd8bd72
> process-1.2.0.0-3a472e9c66165e506513ea8f145681a0
> time-1.4.2-d6766dce59812a4b19375d9595549a8b
> unix-2.7.0.1-8adde3f1f2079286da56b30898c2d703
> (use -v for more information)
> )
> blaze-builder-0.3.3.4 depends on text-1.2.0.0 which failed to install.
> data-binary-ieee754-0.4.4 depends on binary-0.7.2.2 which failed to
> install.
> hosc-0.15 depends on binary-0.7.2.2 which failed to install.
> network-2.6.0.2 failed during the configure step. The exception was:
> user error (<command line>: cannot satisfy -package-id
> Cabal-1.20.0.2-b862897337f86101d0e1a35135984eff:
> Cabal-1.20.0.2-b862897337f86101d0e1a35135984eff is unusable due to
> missing or
> recursive dependencies:
> base-4.7.0.1-df210ede1eb79477fef5662549c32927
> bytestring-0.10.4.0-4aa78c8ca7b6b65993eefc131f7d94fa
> containers-0.5.5.1-0d8db9193d3e3371e0142bcc8a4a0721
> deepseq-1.3.0.2-8f63133c1b77f3b3190f04893cf340e4
> directory-1.2.1.0-af5afa2b9b551d3fec1a32d6bfd8bd72
> process-1.2.0.0-3a472e9c66165e506513ea8f145681a0
> time-1.4.2-d6766dce59812a4b19375d9595549a8b
> unix-2.7.0.1-8adde3f1f2079286da56b30898c2d703
> (use -v for more information)
> )
> text-1.2.0.0 failed during the configure step. The exception was:
> user error (<command line>: cannot satisfy -package-id
> Cabal-1.20.0.2-b862897337f86101d0e1a35135984eff:
> Cabal-1.20.0.2-b862897337f86101d0e1a35135984eff is unusable due to
> missing or
> recursive dependencies:
> base-4.7.0.1-df210ede1eb79477fef5662549c32927
> bytestring-0.10.4.0-4aa78c8ca7b6b65993eefc131f7d94fa
> containers-0.5.5.1-0d8db9193d3e3371e0142bcc8a4a0721
> deepseq-1.3.0.2-8f63133c1b77f3b3190f04893cf340e4
> directory-1.2.1.0-af5afa2b9b551d3fec1a32d6bfd8bd72
> process-1.2.0.0-3a472e9c66165e506513ea8f145681a0
> time-1.4.2-d6766dce59812a4b19375d9595549a8b
> unix-2.7.0.1-8adde3f1f2079286da56b30898c2d703
> (use -v for more information)
> )
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20141028/6c9371d9/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 76, Issue 28
*****************************************