haskell

Implementing Iota in Haskell

若如初见. 提交于 2020-01-01 04:56:01
问题 Iota is a ridiculously small "programming language" using only one combinator. I'm interested in understanding how it works, but it would be helpful to see the implementation in a language I'm familiar with. I found an implementation of the Iota programming language written in Scheme. I've been having a little trouble translating it to Haskell though. It's rather simple, but I'm relatively new to both Haskell and Scheme. How would you write an equivalent Iota implementation in Haskell? (let

Juggling existentials without unsafeCoerce

别说谁变了你拦得住时间么 提交于 2020-01-01 04:47:08
问题 Lately I have been playing with this type, which I understand to be an encoding of the free distributive functor (for tangential background on that, see this answer): data Ev g a where Ev :: ((g x -> x) -> a) -> Ev g a deriving instance Functor (Ev g) The existential constructor ensures I can only consume an Ev g by supplying a polymorphic extractor forall x. g x -> x , and that the lift and lower functions of the free construction can be given compatible types: runEv :: Ev g a -> (forall x.

Using Overloaded Strings

痴心易碎 提交于 2020-01-01 04:45:09
问题 OverloadedStrings extension is really very useful, however it has some downsides. Consider the following function definition: someFunction :: ToJSSTring a => a -> IO () someFunction = js_function . toJSSTring In this case when if I want to pass a literal value I have to add a type signature explicitly when OverloadedStrings is enabled: someFunction ("This is plain string" :: String) someFunction ("And this one is Text" :: Data.Text.Text) The reason for this necessity is quite obvious, I

runST with Hindley-Milner type system

霸气de小男生 提交于 2020-01-01 04:42:05
问题 If I understand the ST monad in Haskell correctly, runST uses rank-2 types in a clever way to ensure that a computation does not reference any other thread when escaping the monad. I have a toy language with a Hindley-Milner type system, and my question is the following: is it possible to extend the HM type system with an ad-hoc rule for typing runST applications so that the ST monad is safely escapable, without introducing rank-2 types? More precisely, runST would have type forall s a. ST s

Is haskellmode-vim dead?

我的未来我决定 提交于 2020-01-01 04:41:05
问题 I just disabled haskellmode-vim from my plugin configurations. Basically this was for three reasons: I prefer neocomplcache for my auto completion needs. Apparently it wasn't updated since 2010. It doesn't seem to be compatible with cabal I hope that someone jumps in the pit and points out that I just have misconfigured the whole thing (as in I configured the most basic thing in the readme). To make this a question: Is it possible to setup haskellmode such that ... ... it gets its

Which Haskell library for computer graphics geometry?

ε祈祈猫儿з 提交于 2020-01-01 04:35:06
问题 I would like to do some experiments in computer graphics in Haskell. This will include doing some geometry calculations and ultimately writing a ray tracer. Which library should I pick for easy handling of vectors, matrices and relevant operations on them? There are few on Hackage including nice looking ones like vect and AC-Vector, but it's easy to miss a good candidate among so many different libraries. 回答1: For vectors and matrices that are used for transformations, vect probably is your

Is there any intuition to understand join two functions in Monad?

前提是你 提交于 2020-01-01 04:34:07
问题 join is defined along with bind to flatten the combined data structure into single structure. From type system view, (+) 7 :: Num a => a -> a could be considered as a Functor , (+) :: Num a => a -> a -> a could be considered as a Functor of Functor , how to get some intuition about it instead of just relying on type system? Why join (+) 7 === 14 ? Even though it is possible to get the final result through manually stepping by the function binding process, it would be great if some intuition

An implementation problem of F# Seq

旧巷老猫 提交于 2020-01-01 04:29:13
问题 I am digging into F# source code recently. in Seq.fs: // Binding. // // We use a type defintion to apply a local dynamic optimization. // We automatically right-associate binding, i.e. push the continuations to the right. // That is, bindG (bindG G1 cont1) cont2 --> bindG G1 (cont1 o cont2) // This makes constructs such as the following linear rather than quadratic: // // let rec rwalk n = { if n > 0 then // yield! rwalk (n-1) // yield n } After seeing the above code, I tested two code: let

How to make Haskell or ghci able to show Chinese characters and run Chinese characters named scripts?

为君一笑 提交于 2020-01-01 04:24:08
问题 I want to make a Haskell script to read files in my /home folder. However there are many files named with Chinese characters, and Haskell and Ghci cannot manage it. It seems Haskell and Ghci aren't good at displaying UTF-8 characters. Here is what I encountered: Prelude> "让Haskell或者Ghci能正确显示汉字并且读取汉字命名的文档" "\35753Haskell\25110\32773Ghci\33021\27491\30830\26174\31034\27721\23383\24182\19988\35835\21462\27721\23383\21629\21517\30340\25991\26723" 回答1: Prelude> putStrLn "\35753Haskell\25110

The purpose of the Traversable typeclass

随声附和 提交于 2020-01-01 04:20:11
问题 Could someone please explain to me, what is the purpose of the typeclass Traversable ? The typeclass definition is: class (Functor t, Foldable t) => Traversable (t :: * -> *) where So Traversable is a Functor t and Foldable t . The traverse function is a member of Traversable and has the following signature: traverse :: Applicative f => (a -> f b) -> t a -> f (t b) Why does the result have to be wrapped into an applicative? What is the sense of it? I have the following example: module