<div dir="ltr"><div>Hi all.</div><div><br></div><div>Having returned to commercial software development after a 10 year break in environmental regulation and travel, it was not long before I was using my favorite language Haskell, fortunately, as part of my job this time.</div><div><br></div><div>Haskell has changed in many ways since last I used it, and I am having an internal (lack of) knowledge collision with the problem below:</div><div><br></div><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">As set out in the example below, given a polygon as GeoJSON from a Postgis enabled Postgres datasbase, I want to get to a list of Double tuples: [(Double,Double)], using Aeson, to draw some polygons.  I am stopped at the point of dismembering the nested coordinate arrays.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">With Stackage nightly-2016-09-01 ghci, and the series of functions defined at the end of this message, I get a runtime type error regarding Vectors, which baffles me.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">Question 1. Why does Aeson nest the arrays using list syntax around the Array type constructor arguments?</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">Question 2. How do I best convert this part of the AST:</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">"(Array [Array [Array [Number 4.5305923601,Number 50.6585120423],Array [Number 4.5307511543,Number 50.657719833],Array [Number 4.5310580333,Number 50.657539732],Array [Number 4.5309023972,Number 50.6584422261],Array [Number 4.5308797482,Number 50.6586166629],Array [Number 4.5305923601,Number 50.6585120423]]])"</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">to a list of Double tuples?</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">I've tried several variations of the function dropOuterArray to try and resolve this run-time error, with no success.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">All help welcome, and thanks for your time</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">Mike.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">========= GHCI Session With Error ======================</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">p = parseGeoJSONGeometry "{\"type\":\"Polygon\",\"coordinates\":[[[4.5305923601,50.6585120423],[4.5307511543,50.657719833],[4.5310580333,50.657539732],[4.5309023972,50.6584422261],[4.5308797482,50.6586166629],[4.5305923601,50.6585120423]]]}"</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal">p (Just (String "Polygon"),Just (Array [Array [Array [Number 4.5305923601,Number 50.6585120423],Array [Number 4.5307511543,Number 50.657719833],Array [Number 4.5310580333,Number 50.657539732],Array [Number 4.5309023972,Number 50.6584422261],Array [Number 4.5308797482,Number 50.6586166629],Array [Number 4.5305923601,Number 50.6585120423]]]))</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal">p1 = dropOuterArrayJ (snd p)</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal">p1 [Array [Array [Number 4.5305923601,Number 50.6585120423],Array [Number 4.5307511543,Number 50.657719833],Array [Number 4.5310580333,Number 50.657539732],Array [Number 4.5309023972,Number 50.6584422261],Array [Number 4.5308797482,Number 50.6586166629],Array [Number 4.5305923601,Number 50.6585120423]]]</p><p style="margin:0px;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal">p2 = dropOuterArray p1</p><div><b></b><i></i><u></u><sub></sub><sup></sup><strike><br></strike></div><div><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">:151:21: error: • Couldn't match type ‘Data.Vector.Vector Value’ with ‘Value’ Expected type: Value Actual type: Array • In the first argument of ‘dropOuterArray’, namely ‘p1’ In the expression: dropOuterArray p1 In an equation for ‘p2’: p2 = dropOuterArray p1</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">============ Code ====================</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">{-# LANGUAGE OverloadedStrings, DeriveGeneric, DeriveAnyClass, ScopedTypeVariables, LambdaCase, FlexibleContexts #-}</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">module GeoJSONGeometry (<br>    parseGeoJSONGeometry<br>    ,Coordinates<br>    ,dropOuterArrayJ<br>    ,dropOuterArray<br>    ,Pt<br>    ,gTypeString<br>) where</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">import Data.Aeson<br>import Data.Aeson.Types --(parse, parseMaybe, parseEither, Value(..))<br>import GHC.Generics<br>import Data.ByteString.Lazy.Char8<br>import Data.HashMap.Strict<br>import qualified Data.Vector as V <br>import Data.Either.Extra (fromRight)<br>import Data.Maybe (fromJust)<br>import Control.Applicative</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">import Codec.Picture<br>import Graphics.Rasterific<br>import Graphics.Rasterific.Texture</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">import GHC.Generics</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)"><br>parseGeoJSONGeometry gjg =<br> let<br>    eresult = (eitherDecode (pack gjg)) :: Either String Object -- Value -- Object<br>    result = (fromRight eresult)<br>    gType = Data.HashMap.Strict.lookup "type" result<br>    gCoords = Data.HashMap.Strict.lookup "coordinates" result<br> in<br>    (gType, gCoords)</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)">gTypeString (Just (Data.Aeson.Types.String s)) = s<br>   <br>dropOuterArrayJ (Just (Array u)) = u</p><p style="margin:0px 0px 1em;padding:0px;border:0px;text-align:left;color:rgb(36,39,41);text-transform:none;line-height:19.5px;text-indent:0px;letter-spacing:normal;clear:both;font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;font-style:normal;font-weight:normal;word-spacing:0px;white-space:normal;background-color:rgb(255,255,255)"><br>dropOuterArray (Array u) = u<br></p></div><div><br></div></div>