[Haskell-cafe] chr/ord?
michael rice
nowgate at yahoo.com
Tue Apr 28 23:32:05 EDT 2009
Thank guys,
Now what am I misunderstanding in the code below?
I would think that
*Main> comb (Just 65) foo
and
*Main> comb (lookup 'A' lst) foo
would return the same result
Just 'A'
Michael
===========Haskell code=============
import Data.Char
lst = [('A',65),('B',66),('C',67),('D',68)]
-- comb is a combinator for sequencing operations that return Maybe
comb :: Maybe a -> (a -> Maybe b) -> Maybe b
comb Nothing _ = Nothing
comb (Just x) f = f x
foo :: Int -> Maybe Char
foo n = Just (chr n)
================Ghci===========
[michael at localhost ~]$ ghci
GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Prelude> :load test1
[1 of 1] Compiling Main ( test1.hs, interpreted )
Ok, modules loaded: Main.
*Main> comb (Just 65) foo
Just 'A'
*Main> comb Nothing foo
Nothing
*Main> lookup 'A' lst
Just 65
*Main> (lookup 'A' lst)
Just 65
*Main> comb (lookup 'A' lst) foo
<interactive>:1:22:
Couldn't match expected type `Integer' against inferred type `Int'
In the second argument of `comb', namely `foo'
In the expression: comb (lookup 'A' lst) foo
In the definition of `it': it = comb (lookup 'A' lst) foo
*Main>
--- On Tue, 4/28/09, Lennart Augustsson <lennart.augustsson at gmail.com> wrote:
From: Lennart Augustsson <lennart.augustsson at gmail.com>
Subject: Re: [Haskell-cafe] chr/ord?
To: "Tim Wawrzynczak" <inforichland at gmail.com>
Cc: "michael rice" <nowgate at yahoo.com>, "haskell-cafe at haskell.org" <haskell-cafe at haskell.org>
Date: Tuesday, April 28, 2009, 10:53 PM
You can also use the more general toEnum and fromEnum.
-- Lennart (iPhone)
On Apr 29, 2009, at 2:13, Tim Wawrzynczak <inforichland at gmail.com> wrote:
Michael, those functions are not in the Prelude, they're in Data.Char.
On Tue, Apr 28, 2009 at 8:08 PM, michael rice <nowgate at yahoo.com> wrote:
Hi,
My Prelude docs must be out of date because chr and ord don't seem to be there. How do I access these functions?
Michael
===============
[michael at localhost ~]$ ghci
GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Prelude> chr 65
<interactive>:1:0: Not in scope: `chr'
Prelude> ord 'A'
<interactive>:1:0: Not in scope: `ord'
Prelude>
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090428/86000b9a/attachment.htm
More information about the Haskell-Cafe
mailing list