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. Couldn't match expected type with actual type (Alexander _)
2. Re: Couldn't match expected type with actual type (pedromartins4)
3. Re: Couldn't match expected type with actual type (Kim-Ee Yeoh)
4. ANN: Haskell Beginners Google+ Community: "Haskell: The
Haskell-Beginners Community" (Benjamin L. Russell)
5. State help request (Joe)
6. Type of function or type of the output of function?
(Trung Quang Nguyen)
7. Re: Type of function or type of the output of function?
(divyanshu ranjan)
----------------------------------------------------------------------
Message: 1
Date: Fri, 7 Dec 2012 20:02:23 +0600
From: Alexander _ <[email protected]>
Subject: [Haskell-beginners] Couldn't match expected type with actual
type
To: [email protected]
Message-ID:
<cafpzw8-r2xp4-fxirp7olhcyh6emx_pdxkuqunssevquqqm...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Hello,
I have function with following signature:
get :: a -> Value b
I don't know concrete type of b. It can be Value Int or Value String or
something else. How can i to write function only for testing? I need
something like this:
get :: a -> Value b
get k = (Value "some_data"')
but i got error:
Couldn't match expected type `b' with actual type `[Char]'
`b' is a rigid type variable bound by
the type signature for get :: a -> Value b
at Test.hs:39:8
In the first argument of `Value', namely `"some_data"'
In the expression: (Value "some_data")
In an equation for `get': get k = (Value "some_data")
Failed, modules loaded: none.
Value data declaration:
data Value b = Value b deriving (Show)
Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121207/eb0a9fd5/attachment-0001.htm>
------------------------------
Message: 2
Date: Fri, 7 Dec 2012 14:18:35 +0000
From: pedromartins4 <[email protected]>
Subject: Re: [Haskell-beginners] Couldn't match expected type with
actual type
To: Alexander _ <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1
Hi Alexander:
You DO know the concrete type of b in the context of get: its necessarily a
String.
Therefore,
get :: a -> Value String
get k = Value "some_data"
works ok.
Also, you can make the type of get polymorphic (accepting different data types)
by writing
get :: a -> Value a
get k = Value k
where whatever the type of a is, get will return Value of that type (Value a).
This works ok because the type of your data type is also polymorphic:
data Value b = Value b deriving (Show)
i.e., b can be something of any type.
Hope this helps.
Cheers,
Pedro
On Dec 7, 2012, at 2:02 PM, Alexander _ wrote:
> Hello,
>
> I have function with following signature:
>
> get :: a -> Value b
>
> I don't know concrete type of b. It can be Value Int or Value String or
> something else. How can i to write function only for testing? I need
> something like this:
>
> get :: a -> Value b
> get k = (Value "some_data"')
>
> but i got error:
>
> Couldn't match expected type `b' with actual type `[Char]'
> `b' is a rigid type variable bound by
> the type signature for get :: a -> Value b
> at Test.hs:39:8
> In the first argument of `Value', namely `"some_data"'
> In the expression: (Value "some_data")
> In an equation for `get': get k = (Value "some_data")
> Failed, modules loaded: none.
>
> Value data declaration:
>
> data Value b = Value b deriving (Show)
>
>
> Thank you.
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 3
Date: Fri, 7 Dec 2012 21:33:16 +0700
From: Kim-Ee Yeoh <[email protected]>
Subject: Re: [Haskell-beginners] Couldn't match expected type with
actual type
To: Alexander _ <[email protected]>
Cc: [email protected]
Message-ID:
<capy+zdrctxqurcuh9nv79fw0tedtqkddl4fswizupx7tbqg...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
See, with a function like
> head :: [a] -> a
the "a" is a type variable that's _specified_ by the caller of the
function.
E.g. if I call
> head "asdf"
the head function gets the type Char, and therefore, it's obligated to also
return a Char.
So if you stick with the original signature of
> get :: a -> Value b
the caller gets to decide the type of both "a" and "b". How do we even know
whether "Value b" is inhabited for any given type "b"?
The only way we can be sure is if the type constructor Value is a constant,
e.g.
> data Value b = Value ()
which makes your get function trivial and therefore highly likely /not/
what you want:
> get = const $ Value ()
If you read up on parametric polymorphism all of this will become clear to
you.
Also, there's a whiff of OO-ness about what you're trying to do. As with
all questions of this type the standard answer applies: consider
re-evaluating what you're trying to accomplish.
-- Kim-Ee
On Fri, Dec 7, 2012 at 9:02 PM, Alexander _
<[email protected]>wrote:
> Hello,
>
> I have function with following signature:
>
> get :: a -> Value b
>
> I don't know concrete type of b. It can be Value Int or Value String or
> something else. How can i to write function only for testing? I need
> something like this:
>
> get :: a -> Value b
> get k = (Value "some_data"')
>
> but i got error:
>
> Couldn't match expected type `b' with actual type `[Char]'
> `b' is a rigid type variable bound by
> the type signature for get :: a -> Value b
> at Test.hs:39:8
> In the first argument of `Value', namely `"some_data"'
> In the expression: (Value "some_data")
> In an equation for `get': get k = (Value "some_data")
> Failed, modules loaded: none.
>
> Value data declaration:
>
> data Value b = Value b deriving (Show)
>
>
> Thank you.
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121207/c7376cab/attachment-0001.htm>
------------------------------
Message: 4
Date: Sat, 08 Dec 2012 08:02:05 +0900
From: [email protected] (Benjamin L. Russell)
Subject: [Haskell-beginners] ANN: Haskell Beginners Google+ Community:
"Haskell: The Haskell-Beginners Community"
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
I have just created a new Haskell beginners Google+ community, "Haskell:
The Haskell-Beginners Community" (see
https://plus.google.com/communities/101629034466170191725).
Feel free to join and contribute!
-- Benjamin L. Russell
--
Benjamin L. Russell / DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile: +011 81 90-6526-1406
"Furuike ya, kawazu tobikomu mizu no oto." -- Matsuo Basho^
------------------------------
Message: 5
Date: Fri, 7 Dec 2012 23:03:39 -0500
From: Joe <[email protected]>
Subject: [Haskell-beginners] State help request
To: [email protected]
Message-ID:
<CAL5Yfc+7HBXT6rq=1w-svng9enygrvbm4pmf+wjjfuothtz...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
below is an implementation of RC4, which I started after Andrew
Gwozdziewycz from NY Hack & Tell encouraged the group to write it. I
mostly followed the pseudocode on Wikipedia.
I'd appreciate any feedback, but I'm most distressed by the KSA
generation, and would like suggestions for making either version less
nasty.
Thanks.
import Data.Bits
import Data.Vector ((!),(//),Vector,fromList)
import Data.Char
import Control.Monad.State
type PRGA = (Vector Int,Int,Int)
type Key = [Int]
-- identity permutation
permId :: Vector Int
permId = fromList [0..255]
-- generate initial PRGA
ksa :: Key -> PRGA
ksa key = ksaStep permId key 0 0
-- I really don't like passing the counter every time,
ksaStep :: Vector Int -> Key -> Int -> Int -> PRGA
ksaStep s _ 255 _ = (s,0,0)
ksaStep s key i j = let j' = (j + (s!i) + (key !! (i `mod`
keylength))) `mod` 256 in
ksaStep (s // [(i, s!j'), (j',s!i)]) key (i+1) j'
where keylength = length key
-- but I tried wedging it into a State, and it's not any clearer
ksa' :: Key -> PRGA
ksa' key = genPRGA
where genPRGA = snd $ foldl (\s a -> snd $ runState (ksaStep' a) s)
(key,(permId,0,0)) [0..255]
ksaStep' :: Int -> State (Key,PRGA) ()
ksaStep' i = do
(key, (s,_,j)) <- get
let j' = (j + (s!i) + (key !! (i `mod` length(key)))) `mod` 256
s' = s // [(i, s!j'), (j',s!i)]
put (key,(s',i,j'))
-- a round of the PRGA
prgaStep :: State PRGA Int
prgaStep = do
(s,i,j) <- get
let i' = (i + 1) `mod` 256
j' = (j + (s!i')) `mod` 256
s' = s // [(i',s!j'), (j',s!i')]
put (s',i',j')
return (s!((s'!i' + s'!j') `mod` 256))
keyStream :: PRGA -> [Int]
keyStream p = let (i,p') = runState prgaStep p
in i : keyStream p'
crypt :: Key -> [Int] -> [Int]
crypt k m = zipWith xor m $ keyStream $ ksa k
pwCrypt :: String -> String -> [Int]
pwCrypt ks ms = crypt key msg
where key = map ord ks
msg = map ord ms
pwDecrypt :: String -> [Int] -> String
pwDecrypt k c = map chr $ crypt key c
where key = map ord k
------------------------------
Message: 6
Date: Sat, 8 Dec 2012 10:11:27 +0100
From: Trung Quang Nguyen <[email protected]>
Subject: [Haskell-beginners] Type of function or type of the output of
function?
To: beginners <[email protected]>
Message-ID:
<cals5ubw9ddn7_npwfwkps0oshvsinfrvndb9q1zufkqiboi...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi there,
I have a quickSort implementation, then I try to use :t in ghci to inspect
what type I receive. I got this.
*Main> :t quickSort "Hello the world"
quickSort "Hello the world" :: [Char]
*Main> :t quickSort [3,2, 1,-10]
quickSort [3,2, 1,-10] :: (Num a, Ord a) => [a]
The first one looks like :t return type of output of quickSort [Char]
The second one looks like :t return the type of function (Num a, Ord a) =>
[a]
Anybody know why this happens? When we will receive type of output, or type
of function? And why (Num a, Ord a) => [a], even quickSort doesn't have
explicit type, so this type comes from input type and type of function is
defined in runtime?
Thanks a lot!
Cheers,
Trung
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121208/2c67de93/attachment-0001.htm>
------------------------------
Message: 7
Date: Sat, 8 Dec 2012 14:58:12 +0530
From: divyanshu ranjan <[email protected]>
Subject: Re: [Haskell-beginners] Type of function or type of the
output of function?
To: Trung Quang Nguyen <[email protected]>, [email protected]
Message-ID:
<CAL9hw26YpkZYVdM=gk4WrZHHu0XDy5tXw=bPo-jxxef=o22...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi,
The second one looks like :t return the type of function (Num a, Ord a) =>
> [a]
(Num a, Ord a) => [a] is not function, First part is type constraints.
On Sat, Dec 8, 2012 at 2:41 PM, Trung Quang Nguyen <[email protected]>wrote:
> Hi there,
>
> I have a quickSort implementation, then I try to use :t in ghci to inspect
> what type I receive. I got this.
>
> *Main> :t quickSort "Hello the world"
> quickSort "Hello the world" :: [Char]
> *Main> :t quickSort [3,2, 1,-10]
> quickSort [3,2, 1,-10] :: (Num a, Ord a) => [a]
>
> The first one looks like :t return type of output of quickSort [Char]
>
> The second one looks like :t return the type of function (Num a, Ord a) =>
> [a]
>
> Anybody know why this happens? When we will receive type of output, or
> type of function? And why (Num a, Ord a) => [a], even quickSort doesn't
> have explicit type, so this type comes from input type and type of function
> is defined in runtime?
>
> Thanks a lot!
>
> Cheers,
> Trung
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121208/66d47035/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 54, Issue 11
*****************************************