haskell

How to read the implementation code/source code for inbuilt functions in Haskell?

丶灬走出姿态 提交于 2021-02-19 05:31:03
问题 For instance if I would like to read the source code for the default curry function in Prelude, where do I refer? Is there a way to read it's implementation? I tried to search it in Hoogle, but it doesn't give the exact implementation, just the input and output types. I am using GHCI on stack to run haskell.- Hoogle curry 回答1: Like @Lee mentioned in the comments, there is a link for source for many of the functions on hackage. Following this will take you to the source code for curry : -- |

How to read the implementation code/source code for inbuilt functions in Haskell?

霸气de小男生 提交于 2021-02-19 05:30:25
问题 For instance if I would like to read the source code for the default curry function in Prelude, where do I refer? Is there a way to read it's implementation? I tried to search it in Hoogle, but it doesn't give the exact implementation, just the input and output types. I am using GHCI on stack to run haskell.- Hoogle curry 回答1: Like @Lee mentioned in the comments, there is a link for source for many of the functions on hackage. Following this will take you to the source code for curry : -- |

How to read the implementation code/source code for inbuilt functions in Haskell?

て烟熏妆下的殇ゞ 提交于 2021-02-19 05:30:02
问题 For instance if I would like to read the source code for the default curry function in Prelude, where do I refer? Is there a way to read it's implementation? I tried to search it in Hoogle, but it doesn't give the exact implementation, just the input and output types. I am using GHCI on stack to run haskell.- Hoogle curry 回答1: Like @Lee mentioned in the comments, there is a link for source for many of the functions on hackage. Following this will take you to the source code for curry : -- |

Text.Parsec many parser won't fully parse a custom parser

末鹿安然 提交于 2021-02-19 01:31:11
问题 I'm having an issue in which my parser for if-blocks (and Do-While blocks because the problem is the same) won't terminate upon the parsing of the string "fi". An If-Block takes the form of: if P -> p [] Q -> q fi If I use Text.Parsec 's string parser to parse "fi" like how I used it to parse "if" to even enter the loop, the program halts. When I print out what should be evaluated its not even there so the program doesn't even enter the If-Block when it is ended with "fi" . When I remove the

How do I determine type of Haskell functions? [duplicate]

扶醉桌前 提交于 2021-02-19 01:18:05
问题 This question already has an answer here : Type Inference in Haskell for functions (1 answer) Closed 1 year ago . I'm preparing for my exams but there is something I can't understand. functions: tw f x = f (f x) f x y = (y, x) I am able to determine the type of 'f' which is f :: t1 -> t -> (t, t1) but can't determine the type of 'tw'. Supposed type of tw: tw :: (t -> t) -> t -> t thanks! 回答1: Let us analyze the function tw : tw f x = f (f x) tw takes as parameters f and x . At the moment we

How does the presence of the “error” function bear on the purity of Haskell?

倾然丶 夕夏残阳落幕 提交于 2021-02-18 22:09:48
问题 I've always wondered how the Haskell exception system fits in with the whole "Pure functional language" thing. For example see the below GHCi session. GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help Prelude> head [] *** Exception: Prelude.head: empty list Prelude> :t head head :: [a] -> a Prelude> :t error error :: [Char] -> a Prelude> error "ranch" *** Exception: ranch CallStack (from HasCallStack): error, called at <interactive>:4:1 in interactive:Ghci1 Prelude> The type of

Any advantage of using type constructors in type classes?

末鹿安然 提交于 2021-02-18 22:01:16
问题 Take for example the class Functor : class Functor a instance Functor Maybe Here Maybe is a type constructor. But we can do this in two other ways: Firstly, using multi-parameter type classes: class MultiFunctor a e instance MultiFunctor (Maybe a) a Secondly using type families: class MonoFunctor a instance MonoFunctor (Maybe a) type family Element type instance Element (Maybe a) a Now there's one obvious advantage of the two latter methods, namely that it allows us to do things like this:

What does '@' mean in Haskell?

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-18 21:43:18
问题 I've tried googling but come up short. I am furthering my Haskell knowledge by reading some articles and I came across one that uses a syntax I've never seen before. An example would be: reconstruct node@(Node a b c l r) parent@(Node b d le ri) I've never seen these @'s before. I tried searching online for an answer but came up short. Is this simply a way to embed tags to help make things clearer, or do they have an actual impact on the code? 回答1: It is used in pattern matching. Now node

Can every functional language be lazy?

允我心安 提交于 2021-02-18 21:29:33
问题 In a functional language, functions are first class citizens and thus calling them is not the only thing I can do. I can also store them away. Now when I have a language, which is strict by default, then I am still not forced to evaluate a function call. I have the option to store the function and its parameters e.g. in a tuple for later evaluation. So instead of x = f a b c I do something like x = (f,a,b,c) And later, I can evaluate this thing with something like eval (f,a,b,c) = f a b c

Read file with UTF-8 in Haskell as IO String

时间秒杀一切 提交于 2021-02-18 21:13:32
问题 I have the following code which works fine unless the file has utf-8 characteres : module Main where import Ref main = do text <- getLine theInput <- readFile text writeFile ("a"++text) (unlist . proc . lines $ theInput) With utf-8 characteres I get this: hGetContents: invalid argument (invalid byte sequence) Since the file I'm working with has UTF-8 characters, I would like to handle this exception in order to reuse the functions imported from Ref if possible. Is there a way to read a UTF-8