haskell

How do experienced Haskell developers approach laziness at *design* time?

孤街醉人 提交于 2020-01-10 06:41:25
问题 I'm an intermediate Haskell programmer with tons of experience in strict FP and non-FP languages. Most of my Haskell code analyzes moderately large datasets (10^6..10^9 things), so laziness is always lurking. I have a reasonably good understanding of thunks, WHNF, pattern matching, and sharing, and I've been able to fix leaks with bang patterns and seq, but this profile-and-pray approach feels sordid and wrong. I want to know how experienced Haskell programmers approach laziness at design

Running a Haskell program on the Android OS

扶醉桌前 提交于 2020-01-10 06:14:27
问题 Forenote: This is an extension of the thread started on /r/haskell Lets start with the facts: Android is one awesome Operating System Haskell is the best programming language on the planet Therefore, clearly, combining them would make Android development that much better. So essentially I would just like to know how I can write Haskell programs for the Android OS. My question is: How can I get a Haskell program to execute/run on the Android OS? 回答1: How you do it is by first getting a Haskell

Creating an instance of the Fractional Typeclass in Haskell

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-10 05:23:29
问题 I am a self-taught Haskell enthusiast and I was building a new type called Physical which I could use to represent physical quantities. It uses two Float s representing the value of the physical quantity and its uncertainty respectively. data Physical = Physical { value :: Float, err :: Float } I used standard rules for the uncertainty of a sum, difference and a product of two quantities to define an instance of the Num typeclass. instance Num Physical where (Physical v1 u1) + (Physical v2 u2

What does the => sign mean in Haskell?

徘徊边缘 提交于 2020-01-10 05:13:04
问题 For some reason I can't find the answer to this anywhere. I tried Googling "Haskell equal sign arrow" and I'm not getting any results. Let's say we have the following function: sendMessage :: MonadM e m => Message -> m () sendMessage message = do mClient <- getMessageClient liftIO $ send mClient message Where exactly are e and m getting used? Are they being passed into the Message object (function?) and then outputted as a single type, m ()? I don't think it helps that I'm very new to Haskell

creating custom instance of UArray

落爺英雄遲暮 提交于 2020-01-10 03:59:09
问题 Suppose I have a simple data type like: data Cell = Open | Blocked and I'd like to use a UArray Int Cell . Is there an easy way to do this? Can I somehow reuse the definition for UArray Int Bool ? 回答1: This answer explains why Vectors are better than Arrays, so I'm going to give you the answer for unboxed vectors. I did try deriving an MArray and IArray instance for Cell based on the Bool instances, but the Bool instances are quite complicated; it would be at least as ugly as manually

Why do Maybe/Optional types use a Just/Some type instead of the actual type?

↘锁芯ラ 提交于 2020-01-10 03:47:25
问题 In Idris, the Maybe type is defined as followed: data Maybe a = Just a | Nothing It's defined similarly in Haskell: data Maybe a = Just a | Nothing deriving (Eq, Ord) Here's the ML version: datatype 'a option = NONE | SOME of 'a What are the benefits of using Just and Some ? Why not define the type without them? example: data Maybe a = a | Nothing 回答1: What would then be the difference between Maybe a and Maybe (Maybe a) ? There's supposed to be a difference between Nothing and Just Nothing .

Haskell dynamic library

强颜欢笑 提交于 2020-01-10 01:43:06
问题 http://www.vex.net/~trebla/haskell/so.xhtml describes how to compile shared library. About compiling command: ghc -O2 -dynamic -shared -fPIC -o libEval.so Eval.hs hsbracket.c -lHSrts-ghc7.6.3 it says: (Could you omit -dynamic to request static libraries of other packages? Not really, they were not generated with -fPIC. In particular it is illegal on x86_64.) Why is it so? What should one do to compile shared library without libHS* dependencies? 回答1: Since Kaiko contacted me privately for an

What's the practical value of all those newtype wrappers in `Data.Monoid`?

不想你离开。 提交于 2020-01-09 19:51:15
问题 When looking at Data.Monoid , I see there are various newtype wrappers, such as All , Sum , or Product , which encode various kinds of monoids. However, when trying to use those wrappers, I can't help but wonder what's the benefit over using their non- Data.Monoid counterparts. For instance, compare the rather cumbersome summation print $ getSum $ mconcat [ Sum 33, Sum 2, Sum 55 ] vs. the more succinct idiomatic variant print $ sum [ 33, 2, 55 ] But what's the point? Is there any practical

What's the practical value of all those newtype wrappers in `Data.Monoid`?

▼魔方 西西 提交于 2020-01-09 19:51:05
问题 When looking at Data.Monoid , I see there are various newtype wrappers, such as All , Sum , or Product , which encode various kinds of monoids. However, when trying to use those wrappers, I can't help but wonder what's the benefit over using their non- Data.Monoid counterparts. For instance, compare the rather cumbersome summation print $ getSum $ mconcat [ Sum 33, Sum 2, Sum 55 ] vs. the more succinct idiomatic variant print $ sum [ 33, 2, 55 ] But what's the point? Is there any practical

What's the practical value of all those newtype wrappers in `Data.Monoid`?

邮差的信 提交于 2020-01-09 19:50:48
问题 When looking at Data.Monoid , I see there are various newtype wrappers, such as All , Sum , or Product , which encode various kinds of monoids. However, when trying to use those wrappers, I can't help but wonder what's the benefit over using their non- Data.Monoid counterparts. For instance, compare the rather cumbersome summation print $ getSum $ mconcat [ Sum 33, Sum 2, Sum 55 ] vs. the more succinct idiomatic variant print $ sum [ 33, 2, 55 ] But what's the point? Is there any practical