Thomas Koster | 31 Aug 02:16 2015
Picon

Stack and packages not in the snapshot

Good morning list,

I have started to use stack with Stackage LTS for building my projects
because I like the idea of a stable snapshot of packages known to work
together.

Then I tried to build "x509-util-1.5.2". This package fails to build
and this is already known by upstream.

And lo, "x509-util" is not in Stackage LTS 3.2, which makes sense.

But what surprised me is that stack attempted to build a package not
in the snapshot, when my resolver is "lts-3.2" (and no extra-deps).

Is there a way to configure stack to build packages from the snapshot
only? Or does it already work this way, only trying "x509-util"
because *I* said "stack build x509-util"?

Thanks in advance.
--
Thomas Koster
John Del Rosario | 30 Aug 08:27 2015
Picon

Difficulty understanding the Towers of Hanoi exercise from CIS194

body{font-family:Helvetica,Arial;font-size:13px}
I've just completed the first exercise (Credit Card Number Validation)
and was quite happy with myself.

But moving on to the next exercise I found myself having trouble trying
to understand some parts of the question.

I've solved Towers of Hanoi before with an imperative language,
but I'm having trouble visualising the steps described in this paragraph:

To move n discs (stacked in increasing size) from peg a to peg b using peg c
as temporary storage,
1. move n-1 discs from a to c using b as temporary storage
2. move the top disc from a to b
3. move n-1 discs from c to b using a as temporary storage.

I've never seen the solution described this way before.
So if I start with 5 discs, then for the first step I'll be moving 4 (n-1) discs? But
can't I only move 1 disc at a time?

And step 2 says to move the top disc from a to b. Which disc is the top disc at this point?

I'm still in a very imperative mindset (and having no formal training doesn't help),
but I'm hoping that will improve as I go through this course!

<div>
<div class="bloop_markdown"><p></p></div>
<div class="bloop_original_html">body{font-family:Helvetica,Arial;font-size:13px}<div>I've just completed the first exercise (Credit Card Number Validation)</div>
<div>and was quite happy with myself.</div>
<div><br></div>
<div>But moving on to the next exercise I found myself having trouble trying</div>
<div>to understand some parts of the question.</div>
<div><br></div>
<div>I've solved Towers of Hanoi before with an imperative language,</div>
<div>but I'm having trouble visualising the steps described in this paragraph:</div>
<div><br></div>
<div>
<div>To move n discs (stacked in increasing size) from peg a to peg b using peg c</div>
<div>as temporary storage,</div>
<div>1. move n-1 discs from a to c using b as temporary storage</div>
<div>2. move the top disc from a to b</div>
<div>3. move n-1 discs from c to b using a as temporary storage.</div>
<div><br></div>
<div>I've never seen the solution described this way before.</div>
</div>So if I start with 5 discs, then for the first step I'll be moving 4 (n-1) discs? But<div>can't I only move 1 disc at a time?</div>
<div><br></div>
<div>And step 2 says to move the top disc from a to b. Which disc is the top disc at this point?</div>
<div><br></div>
<div>I'm still in a very imperative mindset (and having no formal training doesn't help),</div>
<div>but I'm hoping that will improve as I go through this course!</div>
<div><div class="bloop_sign"><div><br></div></div></div>
</div>
<div class="bloop_markdown"><p></p></div>
</div>
Miro Karpis | 29 Aug 01:57 2015
Picon

recursion - more elegant solution

Hi haskellers, I have made one recursive function, where


input is:
   nodesIds: [1,2,4,3,5]
   edgesIds: [(3,5),(4,3),(2,4),(1,2)]

and on output I need/have:
   [([1,2,4,3,5],(3,5)),([1,2,4,3],(4,3)),([1,2,4],(2,4)),([1,2],(1,2))]

I have made one function for this, but it seems to me a bit too big and 'ugly'? Please, do you have any hints for a more elegant solution?

joinEdgeNodes' :: [Int] -> [Int] -> [(Int, Int)] -> [([Int], (Int, Int))]
joinEdgeNodes' [] _ [] = []
joinEdgeNodes' [] _  _ = []
joinEdgeNodes'  _ _ [] = []
joinEdgeNodes' (n) (wn) [e] = [(n, e)]
joinEdgeNodes' (n) [] (e:es) = joinEdgeNodes' n edgeNodes es ++ [(edgeNodes, e)]
   where edgeNodes = take 2 n
joinEdgeNodes' (n) (wn) (e:es) = joinEdgeNodes' n edgeNodes es ++ [(edgeNodes, e)]
   where edgeNodes = take edgeNodesLength n
         edgeNodesLength = (length wn) + 1

I call the function with: let l = joinEdgeNodes' nodeIds [] edgeIds



Cheers, 
Miro
<div><div dir="ltr">Hi haskellers, I have made one recursive function, where<div><br></div>
<div><br></div>
<div>input is:</div>
<div>
<div>&nbsp; &nbsp;nodesIds: [1,2,4,3,5]</div>
<div>&nbsp; &nbsp;edgesIds: [(3,5),(4,3),(2,4),(1,2)]</div>
<div><br></div>
<div>and on output I need/have:</div>
<div>&nbsp; &nbsp;[([1,2,4,3,5],(3,5)),([1,2,4,3],(4,3)),([1,2,4],(2,4)),([1,2],(1,2))]</div>
</div>
<div><br></div>
<div>I have made one function for this, but it seems to me a bit too big and 'ugly'? Please, do you have any hints for a more elegant solution?</div>
<div><br></div>
<div>
<div>joinEdgeNodes' :: [Int] -&gt; [Int] -&gt; [(Int, Int)] -&gt; [([Int], (Int, Int))]</div>
<div>joinEdgeNodes' [] _ [] = []</div>
<div>joinEdgeNodes' [] _ &nbsp;_ = []</div>
<div>joinEdgeNodes' &nbsp;_ _ [] = []</div>
<div>joinEdgeNodes' (n) (wn) [e] = [(n, e)]</div>
<div>joinEdgeNodes' (n) [] (e:es) = joinEdgeNodes' n edgeNodes es ++ [(edgeNodes, e)]</div>
<div>&nbsp; &nbsp;where edgeNodes = take 2 n</div>
<div>joinEdgeNodes' (n) (wn) (e:es) = joinEdgeNodes' n edgeNodes es ++ [(edgeNodes, e)]</div>
<div>&nbsp; &nbsp;where edgeNodes = take edgeNodesLength n</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;edgeNodesLength = (length wn) + 1</div>
</div>
<div><br></div>
<div>I call the function with: <span>let l = joinEdgeNodes' nodeIds [] edgeIds</span><br>
</div>
<div><span><br></span></div>
<div><span><br></span></div>
<div><span><br></span></div>
<div>Cheers,&nbsp;</div>
<div>Miro<br>
</div>
</div></div>
Williams, Wes(AWF | 28 Aug 20:31 2015
Picon

applicative style

Awesome, I clearly am off on my understanding.

How could I do this: "foldl (+) 0 estimates <+> (Just . fromIntegral) (length estimates)” without the parenthesis?

Thanks,
Wes

<div>
<div>
<div>
<div>
Awesome, I clearly am off on my understanding.</div>
<div>
<br>
</div>
<div>How could I do this: "<span><span>foldl (+) 0 estimates &lt;+&gt; (Just . fromIntegral) (length estimates)&rdquo; without
 the parenthesis?</span></span>
</div>
<div>
<br>
</div>
<div>
Thanks,</div>
<div>
Wes</div>
<div>
<br>
</div>
</div>
</div>
</div>
Williams, Wes(AWF | 28 Aug 19:12 2015
Picon

applicative style

Hi haskellers, 

I am trying to understand why I get the following error in learning applicative style.

Prelude> let estimates = [5,5,8,8,2,1,5,2]

Prelude> (/) <$> Just $ foldl (+) 0 estimates <*> Just . fromIntegral $ length estimates


<interactive>:54:1:

    Non type-variable argument in the constraint: Fractional (Maybe r)

    (Use FlexibleContexts to permit this)

    When checking that ‘it’ has the inferred type

      it :: forall a r.

            (Fractional (Maybe r), Num a, Num (Int -> Maybe a -> r)) =>

            Maybe r -> Maybe r


All the parts work individually. If use let and assign the parts to x and y it also works.

E.g. This works
let x = Just $ foldl (+) estimates
Let y = Just . fromIntegral $ length estimates
(/) <$> x <*> y

I clearly do not understand exactly how these work. :-)

Thanks for any help,
-wes
<div>
<div>
<div>
<div>Hi haskellers,&nbsp;</div>
</div>
</div>
<div><br></div>
<div>I am trying to understand why I get the following error in learning applicative style.</div>
<div><br></div>
<div>
<p>
Prelude&gt; let estimates = [5,5,8,8,2,1,5,2]</p>
<p>
Prelude&gt; (/) &lt;$&gt; Just $ foldl (+) 0 estimates &lt;*&gt; Just . fromIntegral $ length estimates</p>
<p>
<br></p>
<p>
&lt;interactive&gt;:54:1:</p>
<p>
&nbsp; &nbsp; Non type-variable argument in the constraint: Fractional (Maybe r)</p>
<p>
&nbsp; &nbsp; (Use FlexibleContexts to permit this)</p>
<p>
&nbsp; &nbsp; When checking that &lsquo;it&rsquo; has the inferred type</p>
<p>
&nbsp; &nbsp; &nbsp; it :: forall a r.</p>
<p>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (Fractional (Maybe r), Num a, Num (Int -&gt; Maybe a -&gt; r)) =&gt;</p>
<p>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Maybe r -&gt; Maybe r</p>
</div>
<div><br></div>
<div>All the parts work individually. If use let and assign the parts to x and y it also works.</div>
<div><br></div>
<div>E.g. This works</div>
<div>let x = Just $ foldl (+) estimates</div>
<div>Let y = Just . fromIntegral $ length estimates</div>
<div>(/) &lt;$&gt; x &lt;*&gt; y</div>
<div><br></div>
<div>I clearly do not understand exactly how these work. :-)</div>
<div><br></div>
<div>Thanks for any help,</div>
<div>-wes</div>
</div>
Adam Flott | 27 Aug 17:04 2015

converting a json encoded radix tree to a haskell data type

I'm having trouble converting a JSON encoded Radix tree into a Haskell
data type[1]. I've tried numerous ways to get the FromJSON instances to
handle all cases, but failing miserably.

[1] unfortunately these type layouts are unchangeable as they are auto
generated types from Thrift

Here is a stripped down version of what I'm working with. For the JSON
file, all keys are unknown at parse time. I only know that a key will be
a string and it's value will be another JSON object or a JSON array of
fixed length.

Any help is appreciated.

-- radix.hs --
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}

import Control.Monad (mzero)
import Data.Int
import Data.Typeable

import Data.Aeson
import qualified Data.ByteString.Lazy as BL
import Data.Text.Lazy as TL
import qualified Data.Vector as V

data Things = MkThings {
  thing   :: TL.Text,
  times :: ThingTimes
  } deriving (Show, Eq, Typeable)

data ThingTimes = MkThingtimes {
  ml :: V.Vector Times
  } deriving (Show, Eq, Typeable)

data Times = MkTimes {
  t1 :: Maybe Int32,
  t2 :: Maybe Int32
  } deriving (Show, Eq, Typeable)

instance FromJSON (V.Vector Things) where
  parseJSON _ = return V.empty

decodeRadix ::BL.ByteString -> Either String (V.Vector Things)
decodeRadix = eitherDecode

main :: IO ()
main = do
  j <- BL.readFile "radix.json"
  case decodeRadix j of
    Left err -> error err
    Right r -> print r
-- radix.hs --

-- radix.json --
{
    "a" : {
        "b" : [ 1, 2 ],
        "c" : {
            "d" : [ 3, null ]
        }
    },
    "a2" : { "b2" : [ 4, 5 ] }
}
-- radix.json --

Noah Sluss | 24 Aug 00:06 2015
Picon

Websockets Library

Hello,

I've been trying to use the WebSockets library to connect to the coinbase feed. The library seems to be doing something behind the scenes that I'm not expecting.

Here is my code:
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE OverloadedStrings #-}
 
import Data.Text
import Data.Text.Encoding (decodeUtf8)
import Network.WebSockets
import qualified Data.ByteString.Lazy as LBS
 
main :: IO ()
main = runClient "ws-feed.exchange.coinbase.com" 8080 "/"  handleConnection
handleConnection connection = do
  send connection initSub
  let loop = do
        priceMsg <- receiveDataMessage connection
        print priceMsg
  loop
 
initSub :: Message
initSub = DataMessage $ Text "{\"type\":\"subscribe\", \"product_id\":\"BTC-USD\"}"

When I run this, I get a print out showing a malformed response exception with a Moved permanently message. Now, it also shows the location that I was trying to connect to, which is: "https://ws-feed.exchange.coinbase.com/". 

This isn't right, because the websocket feed uses the wss:// protocol rather than https://. i've tried changing the url to be "wss://ws-feed.exchange.coinbase.com/", but when I try that, dns resolution fails. If I had to guess, I could imagine that it tries to look for "https://wss://ws-feed.exchange.coinbase.com", which would obviously not work. I'm wondering if there is a way within the library to change the protocol that  client uses. If there is, it doesn't seem to be documented. 

Any insights as to what's going on here would be incredibly helpful.

Thanks,
Noah
<div><div dir="ltr">Hello,<div><br></div>
<div>I've been trying to use the WebSockets library to connect to the coinbase&nbsp;feed. The library seems to be doing something behind the scenes that I'm not expecting.</div>
<div><br></div>
<div>Here is my code:</div>
<div>

<blockquote class="gmail_quote">{-# LANGUAGE ViewPatterns #-}<br>{-# LANGUAGE OverloadedStrings #-}<br>
</blockquote>
<div>&nbsp;</div>
<blockquote class="gmail_quote">import Data.Text<br>import Data.Text.Encoding (decodeUtf8)<br>import Network.WebSockets<br>import qualified Data.ByteString.Lazy as LBS<br>
</blockquote>
<div>&nbsp;</div>
<blockquote class="gmail_quote">main :: IO ()<br>main = runClient "<a href="http://ws-feed.exchange.coinbase.com">ws-feed.exchange.coinbase.com</a>" 8080 "/" &nbsp;handleConnection<br>handleConnection connection = do<br>&nbsp; send connection initSub<br>&nbsp; let loop = do<br>&nbsp; &nbsp; &nbsp; &nbsp; priceMsg &lt;- receiveDataMessage connection<br>&nbsp; &nbsp; &nbsp; &nbsp; print priceMsg<br>&nbsp; loop<br>
</blockquote>
<div>&nbsp;</div>
<blockquote class="gmail_quote">initSub :: Message<br>initSub = DataMessage $ Text "{\"type\":\"subscribe\", \"product_id\":\"BTC-USD\"}"</blockquote>
</div>
<div><br></div>
<div>When I run this,&nbsp;I get a print out showing a malformed response exception with a Moved permanently message. Now, it also shows the location that I was trying to connect to, which is: "<a href="https://ws-feed.exchange.coinbase.com/">https://ws-feed.exchange.coinbase.com/</a>".&nbsp;</div>
<div><br></div>
<div>This isn't right, because the websocket feed uses the wss:// protocol rather than https://. i've tried changing the url to be "wss://<a href="http://ws-feed.exchange.coinbase.com/">ws-feed.exchange.coinbase.com/</a>", but when I try that, dns&nbsp;resolution fails. If I had to guess, I could imagine that it tries to look for "https://wss://<a href="http://ws-feed.exchange.coinbase.com">ws-feed.exchange.coinbase.com</a>", which would obviously not work. I'm wondering if there is a way within the library to change the protocol that &nbsp;client uses. If there is, it doesn't seem to be documented.&nbsp;</div>
<div><br></div>
<div>Any insights as to what's going on here would be incredibly helpful.</div>
<div><br></div>
<div>Thanks,</div>
<div>Noah</div>

</div></div>
Debdut Karmakar | 17 Aug 08:25 2015

oddsFrom3 function

I am a haskell beginner and wondering how the following function works (in procedure) :


oddsFrom3 :: [Integer]
oddsFrom3 = map (+2) oddsFrom3


Thanks for your help.

<div>
<p>I am a haskell beginner and wondering how the following function works (in procedure) :</p>
<p><br>oddsFrom3 :: [Integer]<br> oddsFrom3 = map (+2) oddsFrom3</p>
<p><br>Thanks for your help.</p>
</div>
Shishir Srivastava | 15 Aug 14:24 2015
Picon

Partial application and lazy evalutaion

Hi, 

Is partial application feature of functions in haskell a direct outcome of lazy evaluation ? 

i.e Since functions are not evaluated until at the point where results are required this allows haskell functions to be partially applied because they're not evaluated and hence exist as thunk.

Thanks,
Shishir

<div><div dir="ltr">Hi,&nbsp;<div><br></div>
<div>Is partial application feature of functions in haskell a direct outcome of lazy evaluation ?&nbsp;</div>
<div><br></div>
<div>i.e Since functions are not evaluated until at the point where results are required this allows haskell functions to be partially applied because they're not evaluated and hence exist as thunk.</div>
<div><br></div>
<div>Thanks,<br clear="all"><div><div class="gmail_signature"><div dir="ltr">Shishir<br><br>
</div></div></div>
</div>
</div></div>
Dimitri DeFigueiredo | 14 Aug 20:53 2015
Picon

cabal sandbox add-source installs but disappears

Hello all,

I am having "a bit" of an issue trying to use a source dependency with 
cabal. I have a very simple setup with only 2 packages:

~/code/haskell/package-tests/a-package
         a.cabal
         src/MainA.hs

and

~/code/haskell/package-tests/MinhaCommon
         MinhaCommon.cabal
         setup.hs
         src/MainCommon.hs

I have setup a sandbox for the MinhaCommon package and can build it. 
However, the first one (a-package) depends on the second (MinhaCommon). 
So, I also created a sandbox for it as such:

a-package>cabal sandbox init

and that seems to work fine...

Writing a default package environment file to
/Users/dimitri/code/haskell/package-tests/a-package/cabal.sandbox.config
Creating a new sandbox at
/Users/dimitri/code/haskell/package-tests/a-package/.cabal-sandbox

I then add the source package and install...

a-package>cabal sandbox add-source '../MinhaCommon/'
a-package>cabal install --only-dep
Resolving dependencies...
Notice: installing into a sandbox located at
/Users/dimitri/code/haskell/package-tests/a-package/.cabal-sandbox
Configuring MinhaCommon-0.7.0...
Building MinhaCommon-0.7.0...
Installed MinhaCommon-0.7.0
Updating documentation index
/Users/dimitri/code/haskell/package-tests/a-package/.cabal-sandbox/share/doc/x86_64-osx-ghc-7.10.2/index.html

Here's the snag!

a-package>cabal configure
Resolving dependencies...
Configuring a-0.1.0...
cabal: At least the following dependencies are missing:
MinhaCommon ==0.7.0

WTF!? I just installed that!

The cabal file for package 'a' just includes the MinhaCommon package 
thru the build-depends section
(http://pastebin.com/Wpz5845k)
------------------------------------------------
name:                a
version:             0.1.0
build-type:          Simple
cabal-version:       >=1.20
----------------------------------------------
executable a
   main-is:          MainA.hs
   hs-source-dirs:   ./src

   build-depends:      base                  >= 4.4
                     , unordered-containers
                     , unix
                     , process
                     , stm
                     , MinhaCommon           == 0.7.0

   default-language:    Haskell2010
------------------------------------------------

Any pointers on how to get this to build are much appreciated.

Thanks,

Dimitri

William Bryant | 10 Aug 21:13 2015
Picon

IntelliJ Plugin and IDEs for Haskell (gogobebe2 - OP)

Thanks guys. I saw Atom from googling, so I'll try it. :)
<div><div dir="ltr">Thanks guys. I saw Atom from googling, so I'll try it. :)<br>
</div></div>

Gmane