Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6657131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:43:46+00:00 2026-05-26T01:43:46+00:00

I tried to run code from http://gregorycollins.net/posts/2011/10/01/cufp2011/index.html#(43 ) in GHCi, but got Floating point

  • 0

I tried to run code from http://gregorycollins.net/posts/2011/10/01/cufp2011/index.html#(43) in GHCi, but got “Floating point exception, and GHCi quits.

{-# LANGUAGE OverloadedStrings #-}

import           Control.Applicative
import           Data.Aeson
import           Data.Attoparsec (parseOnly)
import           Data.ByteString.Char8  (ByteString)
import qualified Data.ByteString.Char8 as S
import qualified Data.ByteString.Lazy.Char8 as L


------------------------------------------------------------------------------
example1 :: ByteString -> Either String Coord
example1 bs = parseOnly json bs >>= convert
  where
    convert value = case fromJSON value of
                      (Error e)   -> Left e
                      (Success a) -> Right a

example2 :: Coord -> ByteString
example2 c = S.concat $ L.toChunks $ encode c


------------------------------------------------------------------------------
data Coord = Coord { _x :: Double, _y :: Double }
  deriving (Show, Eq)

instance ToJSON Coord where
    toJSON (Coord x y) = object ["x" .= x, "y" .= y]


instance FromJSON Coord where
    parseJSON (Object v) = Coord    <$>
                           v .: "x" <*>
                           v .: "y"

    -- A non-Object value is of the wrong type, so use mzero to fail.
    parseJSON _          = empty

λ> :l JsonExample.hs 
[1 of 1] Compiling Main             ( JsonExample.hs, interpreted )
Ok, modules loaded: Main.
λ> example2 $ Coord 1 1
"Floating point exception
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:43:47+00:00Added an answer on May 26, 2026 at 1:43 am

    The occuring FPE is a GHC bug, see http://hackage.haskell.org/trac/ghc/ticket/5386 for more details.

    You can try to use the http://hackage.haskell.org/package/aeson-native package instead (it’s API compatible to aeson), which avoids using the C++ library that causes this issue (by using blaze-textual-native), or you can try recompiling blaze-textual (and then also recompile aeson so that it picks up the recompiled blaze-textual) in native mode by

    cabal install -fnative
    

    (see https://github.com/mailrank/blaze-textual/blob/master/README.markdown for more details)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to run the following code from http://docs.python.org/library/mmap.html import mmap # write a
i tried to do tutorial from http://developer.android.com/resources/tutorials/opengl/opengl-es20.html But what I wanted was to create
I copied this code from a book and tried to run that , basically
I am new to development. I followed step by step instructions from http://code.google.com/apis/maps/articles/flashmapinwpf.html to
I already tried references from similar question on SO, but hasn't got the appropriate
I'm trying to run the sample code from this Sun tutorial: http://download.oracle.com/javase/6/docs/technotes/guides/rmi/hello/hello-world.html I've copied
For a site I'm building, I import my Jquery code from... http://jqueryjs.googlecode.com/files/jquery-1.3.2.js ...but when
I tried to run this code: #define ROW_CNT 8; #define COLUMN_CNT 24; #define FIRST_COLUMN
I am trying to run code on several cores (I tried both the snow
When I run this code the selected item is not visible. I've already tried

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.