Skip to content

Comment on Hakaru: An embedded probabilistic programming language in Haskellparent

Comments

Use a sum type:

   data Datum = S String | D Double
   
   lst :: [Datum]
   lst = [S "a", D 3.14]
In Python we'd have to write the logic to handle both cases and fail with an exception or do an instanceof check. In Haskell we'd do this by pattern matching on the sum type.
   case (lst !! 42) of
      S n -> -- handle string
      D n -> -- handle number
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.