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.  Infinite type ... or 'not enough type    arguments'...
      (Sean Charles)
   2. Re:  Infinite type ... or 'not enough type        arguments'...
      (Daniel Fischer)
   3.  "Trinary" version of Either (Christopher Howard)
   4.  Simple warp-based server (Michael Xavier)
   5. Re:  "Trinary" version of Either (Antoine Latter)
   6.  Expected / Inferred mis-match and confused! (Sean Charles)
   7. Re:  "Trinary" version of Either (Yitzchak Gale)
   8. Re:  "Trinary" version of Either (Ozgur Akgun)
   9. Re:  Expected / Inferred mis-match and confused! (Antoine Latter)


----------------------------------------------------------------------

Message: 1
Date: Thu, 09 Jun 2011 12:57:47 +0100
From: Sean Charles <[email protected]>
Subject: [Haskell-beginners] Infinite type ... or 'not enough type
        arguments'...
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Further to my recent attempts to scan a CSV file and build a map, I now 
have a foldl calling this with an empty map:

--forwardRoutes :: M.Map String [String] -> Record -> M.Map
forwardRoutes map row =
   case lookup map (row!!0) of
     Nothing -> M.insert (row!!0) [(row !! 1)] map
     Just routes -> M.insert (row!!0) (row!!1):routes map

With the type declaration commented out I get this:
scread.hs:102:46:
     Occurs check: cannot construct the infinite type:
       a = M.Map [(a, b)] [[(a, b)]]
       Expected type: M.Map [(a, b)] [[(a, b)]]
       Inferred type: a
     In the third argument of `M.insert', namely `map'
     In the expression: M.insert (row !! 0) [(row !! 1)] map


and with it 'in#' i get this error instead...
scread.hs:99:52:
     `M.Map' is not applied to enough type arguments
     Expected kind `?', but `M.Map' has kind `* -> * -> *'
     In the type signature for `forwardRoutes':
       forwardRoutes :: M.Map String [String] -> Record -> M.Map

Can anybody help me to understand both problems. I thought I had 
declared the type signature of forwardRoutes correctly but obv. not! LOL

I have seen information that says the "infinite error" message can be 
cured by supplying types so I did......

Thanks again.
Sean




------------------------------

Message: 2
Date: Thu, 9 Jun 2011 14:27:14 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Infinite type ... or 'not enough type
        arguments'...
To: [email protected]
Cc: Sean Charles <[email protected]>
Message-ID: <[email protected]>
Content-Type: Text/Plain;  charset="us-ascii"

On Thursday 09 June 2011, 13:57:47, Sean Charles wrote:
> Further to my recent attempts to scan a CSV file and build a map, I now
> have a foldl calling this with an empty map:
> 
> --forwardRoutes :: M.Map String [String] -> Record -> M.Map
> forwardRoutes map row =
>    case lookup map (row!!0) of
>      Nothing -> M.insert (row!!0) [(row !! 1)] map
>      Just routes -> M.insert (row!!0) (row!!1):routes map

Needs parentheses

    Just routes -> M.insert (row!!0) ((row!!1):routes) map

Without, it's parsed (M.insert (row!!0) (row!!1)) : (routes map)

I'm not in the mood to figure out how the type inference reaches its 
conclusion, I can tell however, that it started inferring the type with the 
Just-branch.

> 
> With the type declaration commented out I get this:
> scread.hs:102:46:
>      Occurs check: cannot construct the infinite type:
>        a = M.Map [(a, b)] [[(a, b)]]
>        Expected type: M.Map [(a, b)] [[(a, b)]]
>        Inferred type: a
>      In the third argument of `M.insert', namely `map'
>      In the expression: M.insert (row !! 0) [(row !! 1)] map
> 
> 
> and with it 'in#' i get this error instead...
> scread.hs:99:52:
>      `M.Map' is not applied to enough type arguments
>      Expected kind `?', but `M.Map' has kind `* -> * -> *'
>      In the type signature for `forwardRoutes':
>        forwardRoutes :: M.Map String [String] -> Record -> M.Map

You forgot the type arguments of Map in the result type.

M.Map is a type constructor taking two arguments, but type arguments of 
(->) must be fully applied type constructors

> 
> Can anybody help me to understand both problems. I thought I had
> declared the type signature of forwardRoutes correctly but obv. not! LOL
> 
> I have seen information that says the "infinite error" message can be
> cured by supplying types so I did......
> 
> Thanks again.
> Sean



------------------------------

Message: 3
Date: Thu, 09 Jun 2011 07:15:54 -0800
From: Christopher Howard <[email protected]>
Subject: [Haskell-beginners] "Trinary" version of Either
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Is there a Haskell package out there that provides a "trinary" version
of Either, i.e., allowing three values instead of two? I can see how
that would be very handy. Defining one obviously wouldn't be difficult,
but it would be helpful if someone else had already developed Monad
bindings and other related stuff.

-- 
frigidcode.com
theologia.indicium.us



------------------------------

Message: 4
Date: Thu, 9 Jun 2011 08:45:41 -0700
From: Michael Xavier <[email protected]>
Subject: [Haskell-beginners] Simple warp-based server
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Hi Haskell Beginners,

I am writing a fairly simple app in haskell that will be used to support
some Ruby on Rails apps at work. The gist of it is that it takes a JSON
request and produces a JSON response. I've figured that strapping it to a
web server will be the easiest way to allow our Rails apps to talk to it
without worrying about IPC and all of that. I looked at yesod and snap and
both seemed to be too much for what I'm asking. It seems to me that the best
approach would be to write up an WAI interface, strap it to a Warp server
and call it a day.

1) Is my reasoning about the approach to take sound or is there an
alternative I haven't considered? My app will have 1 path (or rather won't
care about the request path) and will take its input by just reading the
request body.

2) Could anyone recommend what I need to read to take this approach? I
started looking at Warp and WAI documentation and found I was well over my
head as I have no knowledge of Iterators/Iteratees/Enumerators nor Builders,
but I'm definitely willing to learn if that's what it takes.

-- 
Michael Xavier
http://www.michaelxavier.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110609/b67960f7/attachment-0001.htm>

------------------------------

Message: 5
Date: Thu, 9 Jun 2011 11:18:02 -0500
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] "Trinary" version of Either
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Thu, Jun 9, 2011 at 10:15 AM, Christopher Howard
<[email protected]> wrote:
> Is there a Haskell package out there that provides a "trinary" version
> of Either, i.e., allowing three values instead of two? I can see how
> that would be very handy. Defining one obviously wouldn't be difficult,
> but it would be helpful if someone else had already developed Monad
> bindings and other related stuff.
>

What would the Monad operations do?

> --
> frigidcode.com
> theologia.indicium.us
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



------------------------------

Message: 6
Date: Thu, 09 Jun 2011 17:26:18 +0100
From: Sean Charles <[email protected]>
Subject: [Haskell-beginners] Expected / Inferred mis-match and
        confused!
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Here are the snippets of my code currently hurting my coding ulcer...

routes :: [Record] -> IO ()
routes legodata = do
   let all = foldl forwardRoutes M.empty legodata -- [Record]
   return ()


forwardRoutes :: M.Map String [String] -> Record -> M.Map String [String]
forwardRoutes map row =
   let key = row !! 0 in
   let val = row !! 1 in
   case lookup key map of
     Nothing     -> M.insert key [val] map
     Just routes -> M.insert key val:routes map

-- some 'deductions' by me, probably erroneous, to help me try to figure 
it out
--
--if legodata is [Record]
--   then row is Record  => [Field]
--
-- if map is "String [String]"
--   then key is Field because row is [Field]
--   then val is Field because row is [Field]
--   Field is "String"
--
-- lookup key map => lookup String M.Map String [String]
-- 

If I am fold-ing over [Record] then I assume that the data that is 
passed to the callback function is of the type Record, i.e. a single 
thing from the list of things. Record is defined as [Field] so 
presumably I could use [Field] or Record in my function 'forwardRoutes'.

When I compile the above I get:

scread.hs:92:18:
     Couldn't match expected type `[(Field, b)]'
            against inferred type `M.Map String [String]'
     In the second argument of `lookup', namely `map'
     In the expression: lookup key map
     In the expression:
         case lookup key map of {
           Nothing -> M.insert key [val] map
           Just routes -> M.insert key val : routes map }

I have spent a long time searching and reading and trying to fathom it 
out from first principles but I cannot for the life of me figure out 
where '[(Field, b)]' is coming from! I can smell Field in there because 
Record is typed as [Field], but a tuple? And what is 'b' ?

The 'inferred type' matches what I thought it should be in the error 
message and I am right (I think) in stating that the 'expected type' is 
what it actually got from the code at compile time?!

Help!
:)



------------------------------

Message: 7
Date: Thu, 9 Jun 2011 19:26:52 +0300
From: Yitzchak Gale <[email protected]>
Subject: Re: [Haskell-beginners] "Trinary" version of Either
To: Antoine Latter <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Christopher Howard wrote:
>> Is there a Haskell package out there that provides a "trinary" version
>> of Either, i.e., allowing three values instead of two? I can see how
>> that would be very handy. Defining one obviously wouldn't be difficult,
>> but it would be helpful if someone else had already developed Monad
>> bindings and other related stuff.

Antoine Latter wrote:
> What would the Monad operations do?

It appears that the equivalents of Either (Either a b) c
and Either a (Either b c) could be equally useful.
So perhaps both should be provided inside newtype wrappers.

-Yitz



------------------------------

Message: 8
Date: Thu, 9 Jun 2011 17:34:15 +0100
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] "Trinary" version of Either
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

Hi,

On 9 June 2011 16:15, Christopher Howard <[email protected]>
 wrote:

> a "trinary" version of Either, i.e., allowing three values instead of two
>

I'd probably nest Eithers: Either a (Either b c)

You can also do some nicer trickery using the TypeOperators extension:

{-# LANGUAGE TypeOperators #-}

type Or = Either
infixr 5 `Or`

k :: a `Or` b `Or` c -- Same as "Either a (Either b c)"
k = undefined


HTH,
Ozgur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110609/02ec7dd8/attachment-0001.htm>

------------------------------

Message: 9
Date: Thu, 9 Jun 2011 11:41:49 -0500
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] Expected / Inferred mis-match and
        confused!
To: Sean Charles <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

It is this line:

> Just routes -> M.insert key val:routes map

Function application binds the tightest, so the compiler interprets this as:

> Just routes -> (M.insert key val) : (routes map)

Which is presumably not what you meant.


On Thu, Jun 9, 2011 at 11:26 AM, Sean Charles <[email protected]> wrote:
> Here are the snippets of my code currently hurting my coding ulcer...
>
> routes :: [Record] -> IO ()
> routes legodata = do
> ?let all = foldl forwardRoutes M.empty legodata -- [Record]
> ?return ()
>
>
> forwardRoutes :: M.Map String [String] -> Record -> M.Map String [String]
> forwardRoutes map row =
> ?let key = row !! 0 in
> ?let val = row !! 1 in
> ?case lookup key map of
> ? ?Nothing ? ? -> M.insert key [val] map
> ? ?Just routes -> M.insert key val:routes map
>
> -- some 'deductions' by me, probably erroneous, to help me try to figure it
> out
> --
> --if legodata is [Record]
> -- ? then row is Record ?=> [Field]
> --
> -- if map is "String [String]"
> -- ? then key is Field because row is [Field]
> -- ? then val is Field because row is [Field]
> -- ? Field is "String"
> --
> -- lookup key map => lookup String M.Map String [String]
> --
>
> If I am fold-ing over [Record] then I assume that the data that is passed to
> the callback function is of the type Record, i.e. a single thing from the
> list of things. Record is defined as [Field] so presumably I could use
> [Field] or Record in my function 'forwardRoutes'.
>
> When I compile the above I get:
>
> scread.hs:92:18:
> ? ?Couldn't match expected type `[(Field, b)]'
> ? ? ? ? ? against inferred type `M.Map String [String]'
> ? ?In the second argument of `lookup', namely `map'
> ? ?In the expression: lookup key map
> ? ?In the expression:
> ? ? ? ?case lookup key map of {
> ? ? ? ? ?Nothing -> M.insert key [val] map
> ? ? ? ? ?Just routes -> M.insert key val : routes map }
>
> I have spent a long time searching and reading and trying to fathom it out
> from first principles but I cannot for the life of me figure out where
> '[(Field, b)]' is coming from! I can smell Field in there because Record is
> typed as [Field], but a tuple? And what is 'b' ?
>
> The 'inferred type' matches what I thought it should be in the error message
> and I am right (I think) in stating that the 'expected type' is what it
> actually got from the code at compile time?!
>
> Help!
> :)
>
> _______________________________________________
> 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 36, Issue 25
*****************************************

Reply via email to