Matt Williams | 26 Jun 15:55 2015
Picon

Defining an Instance of Ord

Dear All,

I am trying to produce a Map, where the (tricky) idea is that the key is a pair, (t1, t2), and the key is considered identical under ordering. Thus:

(t1, t2) is the same as (t2, t1) but
(t1, t3) is not the same as (t1,t2).

This LOOKS like a equality definition. However, the Map key typeclass is defined as Ord, which requires me to define compare:
instance Ord Edge where (Edge s1 _) `compare` (Edge s2 _) = s1 `compare` s2

I am a bit stuck on how to use compare to define this type of eqlaity - any pointers very gratefully received.
BW,
Matt

<div><div dir="ltr">
<div>
<div>
<div>
<div>Dear All,<br><br>
</div>I am trying to produce a Map, where the (tricky) idea is that the key is a pair, (t1, t2), and the key is considered identical under ordering. Thus:<br><br>
</div>(t1, t2) is the same as (t2, t1) but<br>
</div>(t1, t3) is not the same as (t1,t2).<br><br>
</div>This LOOKS like a equality definition. However, the Map key typeclass is defined as Ord, which requires me to define compare:<br><span class="">instance</span><span class=""> Ord Edge </span><span class="">where</span><span class="">
  </span><span class="">(</span><span class="">Edge s1 </span><span class="">_</span><span class="">)</span><span class=""> </span><span class="">`</span><span class="">compare</span><span class="">`</span><span class=""> </span><span class="">(</span><span class="">Edge s2 </span><span class="">_</span><span class="">)</span><span class=""> </span><span class="">=</span><span class=""> s1 </span><span class="">`</span><span class="">compare</span><span class="">`</span><span class=""> s2<br><span><br></span></span><span><span class="">I am a bit stuck on how to use compare to define this type of eqlaity - any pointers very gratefully received.<br></span></span><span><span class="">BW,<br></span></span><span><span class="">Matt<br></span></span><br>
</div></div>
Imants Cekusins | 25 Jun 12:48 2015
Picon

basic use of Applicative

module BasicApplicative where

-- 2 arg
upd2:: Int -> Int -> Int
upd2 x1 x2 = x1 * x2

-- 3 arg
upd3:: Int -> Int -> Int -> Int
upd3 x1 x2 x3 = x1 * x2 + x3

-- pure
pureMaybe::Int -> Maybe Int
pureMaybe = pure

pureList::Int -> [Int]
pureList = pure

-- maybe
maybe2::Maybe Int -> Maybe Int -> Maybe Int
maybe2 mi1 mi2 = upd2 <$> mi1 <*> mi2

-- list
list2::[Int] -> [Int] -> [Int]
list2 l1 l2 = upd2 <$> l1 <*> l2

-- same result as list2
list2p::[Int] -> [Int] -> [Int]
list2p l1 l2 = pure upd2 <*> l1 <*> l2

list3::[Int] -> [Int] -> [Int] -> [Int]
list3 l1 l2 l3 = upd3 <$> l1 <*> l2 <*> l3
Imants Cekusins | 24 Jun 21:52 2015
Picon

Functor fmap: how to

There are a few Functor & fmap tutorials. Here is basic use of fmap.
If it leaves you confused, please ignore it.

module FunctorFmap where

{-
why maybe & list?
Functor instances exist for Maybe & List

http://hackage.haskell.org/package/base-4.8.0.0/docs/Data-Functor.html#t:Functor

expand "instances"
-}

-- (a -> b)
add3:: Int -> Int
add3 = (+ 3)

--  maybe
runMaybe::IO ()
runMaybe = do
    print $ maybeFmap $ Just 1
    print $ maybeInfixed $ Just 1
    print $ maybeFmap Nothing
    print $ maybeInfixed Nothing

-- maybeFmap & maybeInfixed do the same thing. different syntax
maybeFmap::Maybe Int -> Maybe Int
maybeFmap = fmap add3

maybeInfixed::Maybe Int -> Maybe Int
maybeInfixed mi = add3 <$> mi

--  list
runList::IO ()
runList = do
    print $ listFmap [1,2]
    print $ listInfixed [1,2]

-- listFmap & listInfixed do the same thing. different syntax
listFmap::[Int] -> [Int]
listFmap = fmap add3

listInfixed::[Int] -> [Int]
listInfixed l = add3 <$> l
Sevcsik András | 24 Jun 16:53 2015
Picon

http-conduit: Changelogs/notes on API changes

Hi,

I'm trying to update the couchdb-conduit package to use the latest (stackage) version of it's dependencies.

Is there any changelog, release notes, or even a blogpost which summarise how the API was changed between different major versions?

And in general, is there a common practice for hackage packages on how are API-breaking changes are communicated?

Cheers
--
Minden jót,
Sevcsik András
<div>
<div dir="ltr">
<span>Hi,</span><div><br></div>
<div>I'm trying to update the couchdb-conduit package to use the latest (stackage) version of it's dependencies.</div>
<div><br></div>
<div>Is there any changelog, release notes, or even a blogpost which summarise how the API was changed between different major versions?</div>
<div><br></div>
<div>And in general, is there a common practice for hackage packages on how are API-breaking changes are communicated?</div>
<div><br></div>
<div>Cheers</div>
</div>
<div dir="ltr">-- <br>
</div>
<div dir="ltr">Minden j&oacute;t,<div>Sevcsik Andr&aacute;s</div>
</div>
</div>
Alan Buxton | 23 Jun 16:48 2015
Picon

ghc-mod and cabal "could not find module Prelude"

Hi

 

I’ve recently set up a new Haskell working environment on Ubuntu 14.04. I installed the Ubuntu packaged version of Haskell platform.

 

My problem is that I can’t now get ghc-mod check to work if there is a cabal file in the current directory.

 

 

I am using:

·       ghc-mod 5.2.1.2 compiled by GHC 7.6.3

·       cabal 1.16.0.2

 

See below an extract of trying to run ghc-mod check in a directory that was empty until I just ran cabal init in it:

 

~/tmp-ghc-mod$ ls

Setup.hs  tmp-ghc-mod.cabal

~/tmp-ghc-mod$ ghc-mod check Setup.hs

Setup.hs:1:1:Could not find module `Prelude'It is a member of the hidden package `base'.Perhaps you need to add `base' to the build-depends in your .cabal file.It is a member of the hidden package `haskell98-2.0.0.2'.Perhaps you need to add `haskell98' to the build-depends in your .cabal file.It is a member of the hidden package `haskell2010-1.1.1.0'.Perhaps you need to add `haskell2010' to the build-depends in your .cabal file.Use -v to see a list of the files searched for.

~/tmp-ghc-mod$ mv tmp-ghc-mod.cabal tmp-ghc-mod.cabal.NOT

~/tmp-ghc-mod$ ls

dist  Setup.hs  tmp-ghc-mod.cabal.NOT

~/tmp-ghc-mod$ ghc-mod check Setup.hs

Setup.hs:2:1:Warning: Top-level binding with no type signature: main :: IO ()

~/tmp-ghc-mod$

 

So… ghc-mod behaves as expected when there is no cabal file, but doesn’t behave as expected if there is a cabal file.

 

My google fu isn’t helping me out on this: the only issues I have seen are to do with a change in format of the cabal file in newer versions of cabal.

 

Any ideas?

 

Thanks

Alan

 

 

<div><div class="WordSection1">
<p class="MsoNormal">Hi<p></p></p>
<p class="MsoNormal"><p>&nbsp;</p></p>
<p class="MsoNormal">I&rsquo;ve recently set up a new Haskell working environment on Ubuntu 14.04. I installed the Ubuntu packaged version of Haskell platform.<p></p></p>
<p class="MsoNormal"><p>&nbsp;</p></p>
<p class="MsoNormal">My problem is that I can&rsquo;t now get ghc-mod check to work if there is a cabal file in the current directory.<p></p></p>
<p class="MsoNormal"><p>&nbsp;</p></p>
<p class="MsoNormal"><p>&nbsp;</p></p>
<p class="MsoNormal">I am using:<p></p></p>
<p class="MsoListParagraph"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span>ghc-mod 5.2.1.2 compiled by GHC 7.6.3<p></p></p>
<p class="MsoListParagraph"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span>cabal 1.16.0.2<p></p></p>
<p class="MsoNormal"><p>&nbsp;</p></p>
<p class="MsoNormal">See below an extract of trying to run ghc-mod check in a directory that was empty until I just ran cabal init in it:<p></p></p>
<p class="MsoNormal"><p>&nbsp;</p></p>
<p class="MsoNormal">~/tmp-ghc-mod$ ls<p></p></p>
<p class="MsoNormal">Setup.hs&nbsp; tmp-ghc-mod.cabal<p></p></p>
<p class="MsoNormal">~/tmp-ghc-mod$ ghc-mod check Setup.hs <p></p></p>
<p class="MsoNormal">Setup.hs:1:1:Could not find module `Prelude'It is a member of the hidden package `base'.Perhaps you need to add `base' to the build-depends in your .cabal file.It is a member of the hidden package `haskell98-2.0.0.2'.Perhaps you need to add `haskell98' to the build-depends in your .cabal file.It is a member of the hidden package `haskell2010-1.1.1.0'.Perhaps you need to add `haskell2010' to the build-depends in your .cabal file.Use -v to see a list of the files searched for.<p></p></p>
<p class="MsoNormal">~/tmp-ghc-mod$ mv tmp-ghc-mod.cabal tmp-ghc-mod.cabal.NOT<p></p></p>
<p class="MsoNormal">~/tmp-ghc-mod$ ls<p></p></p>
<p class="MsoNormal">dist&nbsp; Setup.hs&nbsp; tmp-ghc-mod.cabal.NOT<p></p></p>
<p class="MsoNormal">~/tmp-ghc-mod$ ghc-mod check Setup.hs<p></p></p>
<p class="MsoNormal">Setup.hs:2:1:Warning: Top-level binding with no type signature: main :: IO ()<p></p></p>
<p class="MsoNormal">~/tmp-ghc-mod$ <p></p></p>
<p class="MsoNormal"><p>&nbsp;</p></p>
<p class="MsoNormal">So&hellip; ghc-mod behaves as expected when there is no cabal file, but doesn&rsquo;t behave as expected if there is a cabal file.<p></p></p>
<p class="MsoNormal"><p>&nbsp;</p></p>
<p class="MsoNormal">My google fu isn&rsquo;t helping me out on this: the only issues I have seen are to do with a change in format of the cabal file in newer versions of cabal.<p></p></p>
<p class="MsoNormal"><p>&nbsp;</p></p>
<p class="MsoNormal">Any ideas?<p></p></p>
<p class="MsoNormal"><p>&nbsp;</p></p>
<p class="MsoNormal">Thanks<p></p></p>
<p class="MsoNormal">Alan<p></p></p>
<p class="MsoNormal"><p>&nbsp;</p></p>
<p class="MsoNormal"><p>&nbsp;</p></p>
</div></div>
Bruno Sotelo Klinec | 22 Jun 18:08 2015

Function problem

Hi there! I was hoping you could help me a bit here with making a function. I am asked to write functions to make a mini robot game, which uses these data and types:

data Program = Move Direction Program
                |Radar (Robot -> Point) Program
                |Shoot Point Program
                |Surrender
data Direction = N|S|E|O
type Point = (Int,Int)
data Robot = R1|R2

And then I have to write functions like this:
prog1::Program
prog1 = Move E $ Radar R1 (2,4) $ Radar R2 (5,6) $ Shoot (5,7) prog1

My problem is the function adjust::Direction->Program->Program that takes one direction and a program and moves every shot in that program one unit in the given direction. I can't figure out how to do this, I would really appreciate you could help me, thanks!
<div><div dir="ltr">Hi there! I was hoping you could help me a bit here with making a function. I am asked to write functions to make a mini robot game, which uses these data and types: <br><br>data Program = Move Direction Program<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; |Radar (Robot -&gt; Point) Program<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; |Shoot Point Program<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; |Surrender<br>data Direction = N|S|E|O<br>type Point = (Int,Int)<br>data Robot = R1|R2<br><br>And then I have to write functions like this: <br>prog1::Program<br>prog1 = Move E $ Radar R1 (2,4) $ Radar R2 (5,6) $ Shoot (5,7) prog1<br><br>My problem is the function adjust::Direction-&gt;Program-&gt;Program that takes one direction and a program and moves every shot in that program one unit in the given direction. I can't figure out how to do this, I would really appreciate you could help me, thanks!<br>
</div></div>
Matt Williams | 22 Jun 12:29 2015
Picon

Structural restrictions in type constructor

Dear All,

I wonder if/ how this is possible?

I have a constructor which takes 2 pairs of type t).

However, I want to ensure that the pairs are matched:

MyP = MyP (t, t) (t, t)

But where the first pair contains the same elements as the second, but reversed in order.

Any help much appreciated.

BW,
Matt

<div>
<p dir="ltr">Dear All,</p>
<p dir="ltr">I wonder if/ how this is possible?</p>
<p dir="ltr">I have a constructor which takes 2 pairs of type t).</p>
<p dir="ltr">However, I want to ensure that the pairs are matched:</p>
<p dir="ltr">MyP = MyP (t, t) (t, t)</p>
<p dir="ltr">But where the first pair contains the same elements as the second, but reversed in order.</p>
<p dir="ltr">Any help much appreciated.</p>
<p dir="ltr">BW,<br>
Matt</p>
</div>
Barry DeZonia | 21 Jun 03:29 2015
Picon

Reading binary data into numeric types

Hello,

I need to write some code that will read binary data from a file into various types defined in Data.Int, Data.Word, and the floating types. I am looking to make functions with signatures like Handle->IO Word16 and Handle->IO Int32 and Handle->IO Float and others similarly defined. One complication I am running into is that the data is stored in big endian byte order. So my functions need to be flexible with byte ordering (and I need to determine the endian ordering of the current platform). Anyhow I'm pretty much a newbie and don't know how to do this. For a float in an imperitive language I might read 4 bytes, possibly reorder them based on platform endian value, and interpret the bytes as a float via a ptr. Would the process be similar in Haskell? Pointers appreciated.
<div><div dir="ltr">
<div>Hello,</div>
<div><br></div>
<div>I need to write some code that will read binary data from a file into various types defined in Data.Int, Data.Word, and the floating types. I am looking to make functions with signatures like Handle-&gt;IO Word16 and Handle-&gt;IO Int32 and Handle-&gt;IO Float and others similarly defined. One complication I am running into is that the data is stored in big endian byte order. So my functions need to be flexible with byte ordering (and I need to determine the endian ordering of the current platform). Anyhow I'm pretty much a newbie and don't know how to do this. For a float in an imperitive language I might read 4 bytes, possibly reorder them based on platform endian value, and interpret the bytes as a float via a ptr. Would the process be similar in Haskell? Pointers appreciated.</div>
</div></div>
Matthias Beyer | 20 Jun 21:54 2015
Picon

Help - I'm completely lost with building a really simple app with Snap and Groundhog

Hi,

I am learning Haskell by trying to implement a really simple CRUD like
web app with Snap and Groundhog - and I'm completely lost, cannot get
it to work.

The relevant code is here:

    https://github.com/matthiasbeyer/rate.hs/tree/restart_clean

What the app should be able to do:

    - CRUD Categories, where a category can have several subcategories
      or Ratings
    - CRUD Ratings, where a rating has a title, a description and, of
      course, a rating (something like a number from 0-10)

That's it. Backend should be postgresql, frontend should contain a
list of all categories with all ratings (a simple tree) and each
rating should have its own page where the description is listed.

So, I guess, this is not really complex or anything, but I'm
completely list with both integrating groundhog and heist, the former
beeing my current step.

Can someone digg into my code and tell me what I'm doing wrong? Or
maybe even provide a _good_ tutorial for me? Or even be my mentor for
this? Would be really nice!

Good night, Haskell community!

-- 
Mit freundlichen Grüßen,
Kind regards,
Matthias Beyer

Proudly sent with mutt.
Happily signed with gnupg.
Hi,

I am learning Haskell by trying to implement a really simple CRUD like
web app with Snap and Groundhog - and I'm completely lost, cannot get
it to work.

The relevant code is here:

    https://github.com/matthiasbeyer/rate.hs/tree/restart_clean

What the app should be able to do:

    - CRUD Categories, where a category can have several subcategories
      or Ratings
    - CRUD Ratings, where a rating has a title, a description and, of
      course, a rating (something like a number from 0-10)

That's it. Backend should be postgresql, frontend should contain a
list of all categories with all ratings (a simple tree) and each
rating should have its own page where the description is listed.

So, I guess, this is not really complex or anything, but I'm
completely list with both integrating groundhog and heist, the former
beeing my current step.

Can someone digg into my code and tell me what I'm doing wrong? Or
maybe even provide a _good_ tutorial for me? Or even be my mentor for
this? Would be really nice!

Good night, Haskell community!

--

-- 
Mit freundlichen Grüßen,
Kind regards,
Matthias Beyer

Proudly sent with mutt.
Happily signed with gnupg.
Martin Vlk | 20 Jun 09:19 2015
Picon

Haskell -> JavaScript -> nodejs

Hi,
I can successfully compile a basic Hello World into JavaScript with
ghcjs and run it with nodejs.
But what I ultimately need to do is write a nodejs module in Haskell and
compile down to JavaScript with ghcjs. I need to be able to require
other nodejs modules as well.

Could somebody point me in the right direction? E.g. what approach and
libraries to use...

I have tried a simple thing with jsaddle/lens, but when I try to compile
with ghcjs it is not finding the imported modules, even though when
compiling with ghc it does find them (they are installed using cabal).

Many Thanks
Martin
Matt Williams | 19 Jun 07:51 2015
Picon

Adapting code from an imperative loop

Dear All,

I have been wrestling with this for a while now.

I have a list of data items, and want to be able to access them, in a Hash Map, via a short summary of their characteristics.

In an imperative language this might look like:

myMap = new map()
for elem in myElems:
    key = makeKey(elem)
    myMap[key] = myMap[key] + elem

I have been trying to do this in Haskell, but am stuck on how to hand the Map back to itself each time.

I have a function :: elem -> [p,q] to make the key, but the Map.insert function has the following signature:

insert :: (Hashable k, Ord k) => k -> a -> HashMap k a -> HashMap k a

My thought was that I needed to go through the list of the elems, and at each point add them to the Hash Map, handing the updated Map onto the next step - but this is what I cannot write.

Any help much appreciated.

Thanks,
Matt

   
   

<div>
<p dir="ltr">Dear All,</p>
<p dir="ltr">I have been wrestling with this for a while now.</p>
<p dir="ltr">I have a list of data items, and want to be able to access them, in a Hash Map, via a short summary of their characteristics.</p>
<p dir="ltr">In an imperative language this might look like:</p>
<p dir="ltr">myMap = new map()<br>
for elem in myElems:<br>
&nbsp;&nbsp;&nbsp; key = makeKey(elem)<br>
&nbsp;&nbsp;&nbsp; myMap[key] = myMap[key] + elem</p>
<p dir="ltr">I have been trying to do this in Haskell, but am stuck on how to hand the Map back to itself each time.</p>
<p dir="ltr">I have a function :: elem -&gt; [p,q] to make the key, but the Map.insert function has the following signature:</p>
<p dir="ltr">insert&nbsp;:: (<a href="https://hackage.haskell.org/package/hashmap-1.0.0.2/docs/Data-Hashable.html#t:Hashable">Hashable</a>&nbsp;k,&nbsp;<a href="https://hackage.haskell.org/packages/archive/base/4.2.0.2/doc/html/Data-Ord.html#t:Ord">Ord</a>&nbsp;k) =&gt; k -&gt; a -&gt;&nbsp;<a href="https://hackage.haskell.org/package/hashmap-1.0.0.2/docs/Data-HashMap.html#t:HashMap">HashMap</a>&nbsp;k a -&gt;&nbsp;<a href="https://hackage.haskell.org/package/hashmap-1.0.0.2/docs/Data-HashMap.html#t:HashMap">HashMap</a>&nbsp;k a</p>
<p dir="ltr">My thought was that I needed to go through the list of the elems, and at each point add them to the Hash Map, handing the updated Map onto the next step - but this is what I cannot write.</p>
<p dir="ltr">Any help much appreciated.</p>
<p dir="ltr">Thanks,<br>
Matt</p>
<p dir="ltr">&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; </p>
</div>

Gmane