Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.haskell > #344

Re: How(approaches) to implement implementing lazy evaluation in the C (Imperative Programming)

From Steven Hystad <steven.hystad@lunarinfrastructure.net>
Newsgroups comp.lang.haskell
Subject Re: How(approaches) to implement implementing lazy evaluation in the C (Imperative Programming)
Date 2015-09-19 23:50 -0600
Organization Aioe.org NNTP Server
Message-ID <1442728251.4630.153.camel@epic> (permalink)
References <07c4a873-63a7-4a3a-9318-d0baf50f099f@googlegroups.com>

Show all headers | View raw


On Fri, 2015-09-18 at 07:37 -0700, Chethan U wrote: 
> Hello Sir,
> 
> How to implement implementing lazy evaluation in the C (Imperative Programming)?
> 
> Lazy evaluation is one of the key features in functional programming languages such as Haskell. This feature allows the programmers to work on infinite series quite easily.  Functional programming languages work at higher abstraction focusing on what needs to be done instead of on how it can be done.
> 
> Imperative programming languages focus more on how a goal can be achieved and hence work at a lower level of abstraction.  Therefore, it is natural to ask how such a feature can be implemented in imperative programming languages such as C.
> 
> What are the Various Approaches of implementing lazy evaluation in the C programming language.
> 
> What are the Constructs required for implementing lazy evaluation logic
>  'C' programming language support for the required constructs
> Thanks Sir
You can handle lazy evaluation by simply packing a function pointer,
value, and bool into a struct. If !bool then evaluate function, else
value = function(); bool = true.

Simple. Right?

This gives you lazy evaluation, but failes to do two things that haskell
does for you. In haskell, or at least in GHC, evaluation is thread safe.
One thread can start evaluation, and another can wait for the value
without causing an error. Haskell also has garbage collection. When GHC
decides that a thunk (i.e. the function pointer) will never be evaluated
then GHC can GC the thunk and possibly the data that the thunk depends
on.

That's not so easy.

If you want an easy way to have all the lazy functional programing
advantages of haskell and also want all the speed of C, then maybe try
using GHC and GCC together. .c files can be included in a GHC project
and GHC will automatically forward .c files to GCC. GHC can also handle
linking .o files made by GCC.

So if you can't use GHC, then gook luck.

Back to comp.lang.haskell | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How(approaches) to implement implementing lazy evaluation in the C (Imperative Programming) Chethan U <evolutionmanager123@gmail.com> - 2015-09-18 07:37 -0700
  Re: How(approaches) to implement implementing lazy evaluation in the C (Imperative Programming) fmassei@gmail.com - 2015-09-19 11:35 -0700
    Re: How(approaches) to implement implementing lazy evaluation in the C (Imperative Programming) Unknown <dog@gmail.com> - 2015-10-17 06:38 +0000
  Re: How(approaches) to implement implementing lazy evaluation in the C (Imperative Programming) Steven Hystad <steven.hystad@lunarinfrastructure.net> - 2015-09-19 23:50 -0600
  Re: How(approaches) to implement implementing lazy evaluation in the C (Imperative Programming) He-chien Tsai <depot051@gmail.com> - 2015-11-07 08:17 -0800

csiph-web